How do your on/off/toggle functions work? My solution also updates a global matrix, but my implementation doesn't feel good. Looking forward to seeing nicer solutions.

xind=: 3 : 0&{ + [: i. >:@:(-/)@:(2 0&{)
yind=: 3 : 1&{ + [: i. >:@:(-/)@:(3 1&{)
mkmask=: 3 : '1 inds} 1000 1000 $ 0 [ inds=: < (xind y);(yind y)'
on=: 3 : 'lights=: lights + mkmask y'
off=: 3 : 'lights=: 0 >. lights - mkmask y'
toggle=: 3 : 'lights=: lights + +: mkmask y'
instructions=: <;._2 (' through ';',';'turn ';'') stringreplace fread'/tmp/input.txt'

lights=: 1000 1000$0
do each instructions
+/, lights



On 7 Dec 2015, at 6:35, David Lambert wrote:

After tracking down the rank error my solution sentence became

+/,on`off`toggle@.({.@identify)"1 A

where A is a matrix containing one instruction per row, and the agenda item verbs modify a global matrix. Have you guessed my difficulty? Yes, identify returned a length one vector instead of a scalar.
----------------------------------------------------------------------
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