small mod ( ,@:) results in list instead of a 300 1 shape.

(0 1 2 ,@:#~  ('turn on'&({.@E.) , 'turn off'&({.@E.) , 'toggle'&({.@E.))"1) > 
cutLF a

the reason there doesn't seem a way to get a simple list result without , is 
that there is no guarantee that you would select only 1 item from the rhs.



----- Original Message -----
From: David Lambert <b49p23t...@gmail.com>
To: programming <programm...@jsoftware.com>
Sent: Sunday, December 6, 2015 6:03 PM
Subject: Re: [Jprogramming] adventofcode 6

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