I saw a script for a 1D Rubik's cube on the wiki but I couldn't run it - I seem 
to be missing the appropriate files - so I decided to write my own one to be 
used in the browser. I am trying to allow you to see the move you've made or 
choose not to see it. The idea is that:

   0 move 1

moves the cube but doesn't show you while:

   1 move 1
1 5 4 3 2 6

The default is 1 (based on my understanding of 1&$:).

move=: 1&$: : (4 :0)                                            NB. x is 0 or 1 
to show cube
select. y
        case. 0 do.
        cube=: (_2{. cube) ,~ |. (2-~#cube) {. cube             NB. rotate 
first section
        case. 1 do.
        cube=: ({:cube) ,~ ({.cube) , |. (2-~#cube) {. }.cube   NB. rotate 
middle section
        case. 2 do.
        cube=: (2{. cube) , |. (-2-~#cube) {. cube              NB. rotate end 
section
end.
if. x=1 do. cube end.                                           NB. display cube
)

The main reason I want to do this is so that my shuffle verb can shuffle the 
row without displaying every move its made - only showing the last:

shuffle=: 3 :'(((y-1)$0),1) move"0 ] 3|?~y'

It would seem that in the case statements, whenever anything is assigned, it is 
also displayed - can this be avoided? Also I would appreciate it if anyone 
could clarify how the $: works here (I copied the idea from a verb somewhere in 
the wiki).

Thanks.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to