[Jprogramming] advent day 6 (cycling and adding) (spoilers possible)

Daniel Lyons fusion at storytotell.org
Thu Dec 7 15:03:37 UTC 2017


On Dec 7, 2017, at 7:48 AM, Joe Bogner <joebogner at gmail.com> wrote:
> 
> I'm still working on day 6 and I'm looking for a tip on a specific part I'm
> trying (not the whole solution)
> 
> I'd like to define a verb that cycles through a list N times and adds 1 to
> each element
> 
> 3 addCycle (4#0) -: 1 1 1 0
> 
> 4 addCycle (4#0) -: 1 1 1 1
> 
> 5 addCycle (4#0) -: 2 1 1 1
> 
> 6 addCycle (4#0) -: 2 2 1 1
> 
> 7 addCycle (4#0) -: 2 2 2 1
> 
> I was initially messing around with variants of this (clearly wrong)
> 
> ((1 (0) } ]) + |.)^:3 (0 0 0 0)
> 
> I also wonder if there's some antibase pattern or odometer solution


I also got hung up on this part and haven’t solved it yet.

My thought was to use copy to generate a bunch of 1s, up to the size of the number of buckets, and fill in with 0s beyond the number in the bucket, and then do iterated sums. All this under a rotation for the location of the number. In my mind it would look like this:

3 |. 0 2 0 0 = 0 0 2 0
   0 0 2 0 + 1 1 1 1 = 1 1 3 1   NB. 4 gen 7 = 1 1 1 1 ; 3
   1 1 3 1 + 1 1 1 0 = 2 2 4 1   NB. 4 gen 3 = 1 1 1 1 ; 0, the second value being zero terminates the loop
_3 |. 2 2 4 1 = 2 4 1 2

This was the best I could imagine but I don’t have any idea if it’s reasonable or less work than just going around item-by-item, and I haven’t coded it up yet.

-- 
Daniel Lyons






More information about the Programming mailing list