I went with an explicit function for typing speed, but did the transform 
tacitly.  Full tacit had problems 


b is a table where each row is a code, and x1,y1,x2,y2
p2 creates and returns the matrix.


Y =: (&{::)(@:])
X =: (&{::)(@:[)
b =. (2 , 0 ". every  3 5 7 9 { ])`(1 , 0 ". every  3 5 7 9 { ])@.('on' -: 2 
Y)`(0 , 0 ". every  2 4 6 8 { ])@.(0 Y)"1( ],~ [: < 0:`1:@.('toggle' -: 0 Y))"1 
;:"1 > cutLF a =. wd 'clippaste'


p2 =: 3 : 0 
c =. 1000 1000 $ 0 
for_i. y do. 
d =. (0 Y) i 
b =. (,@:(<"1)@(( 2 Y + 4 Y i.@>:@- 2 Y) ,.~"0 1 ( 1 Y + 3 Y i.@>:@- 1 Y))) i
if. d = 1 do. c =. (1 + b{c)  b} c 
elseif. d = 2 do. c=. ( <:^:(0 < ])"0 b{c)  b} c 
elseif. 1 do. c =.  (2 + b{c)  b} c end. 
end. 
) 

+/ +/ p2 b 

----- Original Message -----
From: Ryan Eckbo <ec...@cim.mcgill.ca>
To: programming <programm...@jsoftware.com>
Sent: Sunday, December 6, 2015 4:46 PM
Subject: Re: [Jprogramming] adventofcode 6

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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to