S=: (a.,~,|.t) {~ (a.,~,t=.a.{~97 65+/~i.26)&i.
S 'Hello, World!'
Svool, Dliow!
S 'A man, a plan, a canal, Panama!'
Z nzm, z kozm, z xzmzo, Kzmznz!
On Fri, Jan 22, 2016 at 5:33 PM, Moon S <[email protected]> wrote:
> Here's another code golf challenge I found:
>
> http://www.blonde.net/blog/2016/01/18/blonde-code-golf-january-16
>
> In a string, swap a-z with z-a, A-Z with Z-A. Assume that you will always
> get a valid string and that spaces and special characters should remain
> unchanged.
>
> alphaSwap('abcxyz') // -> zyxcba
> alphaSwap('Hello, World!') // -> Svool, Dliow!
>
> The shortest solution there is in Ruby, 37 chars:
>
> s.gsub(/[a-z]/i){|c|(c.ord+4^31).chr}
>
>
> I did it in J obviously, with and without regex.
>
> A=:'019abcABC|xyzXYZ+='
>
> NB. spoiler......
>
>
>
>
>
>
> NB. my solutions:
>
> '[a-z]'(a.{~219-a.i.])R'[A-Z]'(a.{~155-a.i.])(R=.rxapply_jregex_) A
> (a.{~[:(]+((155-+:)*64&<*.<&91)+(219-+:)*96&<*.<&123)a.&i.) A
> (a.{~((i.65),(65+i._26),(91+i.6),(97+i._26),123+i.133){~a.&i.) A
>
> Definitely there must be a shorter solution for making that reordering
> array...
>
>
> - Georgiy
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm