Part 1:

i =. <@('y =. y ' , ;@(<@('(' , ,&')');._2)@:(,&' '));._2 wd 'clippaste'

through =: (1000 1000 {. ({. ($&1)))/@(-~/\)@:-@(,:~ >:)

turn =: 1 : 'u'

'`off on toggle' =: >`+.`~:

+/@, 3 : i 1000 1000 $ 0


For part 2, use

'`off on toggle' =: (0 >. -)`+`(+ +:)




On 12/6/2015 6:03 PM, David Lambert wrote:
Ryan made a mask shape 1000 1000 and applied it appropriately to a cumulative array. Pascal updated the accumulation array in place. I did so likewise but used the dyadic form of amend with gerund m. Pascal computed the index in one place, which I prefer to my 3 sites.

   g
[: r/ [: _&". {::"0 1

   r   NB. absolute value not required
([ + i.@:|@:(-/)) >:


   NB. noun L is the array of lights.

   identify  NB. whoops!  returns a vector
0 1 2 #~ 'turn on'&({.@E.) , 'turn off'&({.@E.) , 'toggle'&({.@E.)

   on
3 : 0
 I=:([: < 2 6&g ; 4 8&g)@;:y
 NB. L=:I (1:)`([)`(])}L
 L=:I (>:@:{)`([)`(])}L
 EMPTY
)

   off
3 : 0
 I=:([: < 2 6&g ; 4 8&g)@;:y
 NB.I (0:)`([)`(])}L
 L=:I ((0>.<:)@:{)`([)`(])}L
 EMPTY
)

   toggle
3 : 0
 I=:([: < (<:2 6)&g ; (<:4 8)&g)@;:y
 NB. L=:  I (-.@:{)`([)`(])}L
 L=:I (2+{)`([)`(])}L
 EMPTY
)


   NB. what the heck???  Why is this zero?

+/, L [ on`off`toggle@.({.@identify)@,;._2(1!:1)<'/tmp/a' [ L=:1000 1000$0
0
   +/,L
14110788




Date: Mon, 07 Dec 2015 08:46:59 +1100
From: "Ryan Eckbo"<ec...@cim.mcgill.ca>
To: programming<programm...@jsoftware.com>
Subject: Re: [Jprogramming] adventofcode 6
Message-ID:<b4007f86-91ad-409c-95d6-ba6d6966c...@cim.mcgill.ca>
Content-Type: text/plain; format=flowed

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


----------------------------------------------------------------------
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