I would be tempted to express your S like this: SM=: 0 10#: 10* 1+ ".;._2 noun define 0.1 1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 9.1 NB. initial 0.0 1.2 2.2 3.2 4.2 5.2 6.2 7.2 8.2 9.2 NB. 0 0.2 1.0 2.2 3.2 4.2 5.2 6.2 7.2 8.2 9.2 NB. 1 0.2 1.2 2.0 3.2 4.2 5.2 6.2 7.2 8.2 9.2 NB. 2 0.2 1.2 2.2 3.0 4.2 5.2 6.2 7.2 8.2 9.2 NB. 3 0.2 1.2 2.2 3.2 4.0 5.2 6.2 7.2 8.2 9.2 NB. 4 0.2 1.2 2.2 3.2 4.2 5.0 6.2 7.2 8.2 9.2 NB. 5 0.2 1.2 2.2 3.2 4.2 5.2 6.0 7.2 8.2 9.2 NB. 6 0.2 1.2 2.2 3.2 4.2 5.2 6.2 7.0 8.2 9.2 NB. 7 0.2 1.2 2.2 3.2 4.2 5.2 6.2 7.2 8.0 9.2 NB. 8 0.2 1.2 2.2 3.2 4.2 5.2 6.2 7.2 8.2 9.0 NB. 9 )
Changes: I changed the variable name, so it might be easier to refer to a specific way of generating the value. I indented the script. I prefer indented scripts. I got rid of that first row and the corresponding drop verb, subtracted 1 from each literal value (so they correspond to your system) and then add 1 after collecting the values. I added some whitespace between the initial matrix formation and the part that converts it to a rank 3 <next state, operation> array. I also added an extra space before the NB. comments, to make them stand out. I was also tempted to do this: StM=: 0 10#: 10* 1+ ".;._2 noun define 0.1 1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 9.1 NB. initial [0] 0.0 1.2 2.2 3.2 4.2 5.2 6.2 7.2 8.2 9.2 [1] 0.2 1.0 2.2 3.2 4.2 5.2 6.2 7.2 8.2 9.2 [2] 0.2 1.2 2.0 3.2 4.2 5.2 6.2 7.2 8.2 9.2 [3] 0.2 1.2 2.2 3.0 4.2 5.2 6.2 7.2 8.2 9.2 [4] 0.2 1.2 2.2 3.2 4.0 5.2 6.2 7.2 8.2 9.2 [5] 0.2 1.2 2.2 3.2 4.2 5.0 6.2 7.2 8.2 9.2 [6] 0.2 1.2 2.2 3.2 4.2 5.2 6.0 7.2 8.2 9.2 [7] 0.2 1.2 2.2 3.2 4.2 5.2 6.2 7.0 8.2 9.2 [8] 0.2 1.2 2.2 3.2 4.2 5.2 6.2 7.2 8.0 9.2 [9] 0.2 1.2 2.2 3.2 4.2 5.2 6.2 7.2 8.2 9.0 ) But that might be taking things too far... Thanks, -- Raul On Thu, Dec 10, 2015 at 3:52 AM, Ryan Eckbo <ec...@cim.mcgill.ca> wrote: > A previous advent answer got me thinking about state machines, so I wrote > one for this problem. The extra initial state ruins the natural mapping > between states and numbers, but I think it's unavoidable? Also someone > could probably write a clever verb to generate the table. > > > NB. state machine -- can be confusing because rows/states 1,2,3,.. represent > numbers 0,1,2,.. > S=: 0 10#: 10* ". }. [;._2 noun define > 0 1 2 3 4 5 6 7 8 9 > 1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 9.1 10.1 NB. initial > 1.0 2.2 3.2 4.2 5.2 6.2 7.2 8.2 9.2 10.2 NB. 0 > 1.2 2.0 3.2 4.2 5.2 6.2 7.2 8.2 9.2 10.2 NB. 1 > 1.2 2.2 3.0 4.2 5.2 6.2 7.2 8.2 9.2 10.2 NB. 2 > 1.2 2.2 3.2 4.0 5.2 6.2 7.2 8.2 9.2 10.2 NB. 3 > 1.2 2.2 3.2 4.2 5.0 6.2 7.2 8.2 9.2 10.2 NB. 4 > 1.2 2.2 3.2 4.2 5.2 6.0 7.2 8.2 9.2 10.2 NB. 5 > 1.2 2.2 3.2 4.2 5.2 6.2 7.0 8.2 9.2 10.2 NB. 6 > 1.2 2.2 3.2 4.2 5.2 6.2 7.2 8.0 9.2 10.2 NB. 7 > 1.2 2.2 3.2 4.2 5.2 6.2 7.2 8.2 9.0 10.2 NB. 8 > 1.2 2.2 3.2 4.2 5.2 6.2 7.2 8.2 9.2 10.0 NB. 9 > ) > v=:[: ,@:((#,{.)every) (0;S)&;: > smoutput $ v^:40 Input=: 1 1 1 3 2 2 2 1 1 3 > smoutput $ v^:50 Input > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm