Reference: http://rosettacode.org/wiki/Topswops
What are good ways to count iterations?
While=: 2 : 'u^:v^:_'
topswop=: (|.@:{. , }.)~ {.
topswop While (1 ~: {.) 2 4 1 3
1 2 3 4
These ideas seem like structural nightmares:
* separate data and counter with boxes;
* append a counter to the data;
* explicit code with a global noun;
* +/@:(0 = (0,~topswop)While(1 ~: {.)) NB. <laughs>.
The boxes or explicit code seem most general.
Thank you, Dave.
Bonus: find a definition topswop using C.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm