My strategy so far has been to write a preprocessing verb that takes inputs
of the stops and alphabet and makes a noun keys that is just the boxed
encoded forms of each letter in the alphabet. I feel like this works a
little more cleanly, and it has the advantage that a lot of code can be
reused between encode and decode. The verb break here is incorrect and does
not work for two stop characters in a row.
NB. defines encode and decode verbs, to be used later
setcode=:3 :0 NB. stops setcode alphabet
2 6 setcode y
:
alphabet=:y, ,":"0 i.10
order=. (~.x,i.#y) /:~ ' ',8{.y
alphkeys=. 2|.2}. order /:~ ,(($0);<"0 stops) ,&.>/ i.10
esckey=: >(alphabet i. '/'){alphkeys
numkeys=. esckey ,&.> i.10
keys=: alphkeys,numkeys
stops=: x
encode=: [:; keys{~ alphabet&i.
break=: </.~ i.@# - _1|. e.&stops + _1|.2*esckey&E.
decode=: alphabet {~ keys i. break
i.0 0
)
I will look and see how much of your code I can incorporate if it works
better.
Marshall
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ric Sherlock
Sent: Saturday, June 18, 2011 11:59 AM
To: Programming forum
Subject: [Jprogramming] Straddling Checkerboard encoding
I've made a submission for the Rosetta Code Straddling Checkerboard task but
judging by some of the other entries I'm pretty sure that it can be
significantly simplified. Any suggestions?
http://rosettacode.org/wiki/Straddling_checkerboard
(Please feel free to edit the Rosetta Code solution directly if so
inclined!)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm