Alpha_j_    ]`([{~26(([*<.@%~)+<:@[-|)i.)@.(e.~"1 0)'AbcazZ~! Hello, 
World!'
ZyxzaA~! Svool, Dliow!




----- Original Message -----
From: Moon S <[email protected]>
To: programming <[email protected]>
Sent: Friday, January 22, 2016 8:33 PM
Subject: [Jprogramming] Blonde Code Golf - January Challenge - Alphabet Swap

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

Reply via email to