Nice. That said, maybe:
(+ +/@((-@#@[ ]\ (i. $ 0:) , -@] , ] # 1:) >./)) 0 2 7 0 2 4 1 2 Thanks, -- Raul On Thu, Dec 7, 2017 at 10:47 AM, Roger Hui <[email protected]> wrote: > old=: 0 2 7 0 > n =: #old > max=: >./old > i =: old i. max > > ] s=: (-n) ]\ ((1+i)$0), max#1 > 0 0 0 1 > 1 1 1 1 > 1 1 0 0 > +/s > 2 2 1 2 > > ] new=: (0 i}y) + +/s > 2 4 1 2 > > assert (+/old) -: +/new > 1 > > > > On Thu, Dec 7, 2017 at 7:03 AM, Daniel Lyons <[email protected]> wrote: > >> On Dec 7, 2017, at 7:48 AM, Joe Bogner <[email protected]> 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 >> >> >> >> >> ---------------------------------------------------------------------- >> 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
