The (-n)]\blah and the assert, had I applied them from the first, would have saved me many minutes. I attempted to solve it in APL which did not have (-n)]\, so I used ⍴ (AKA $, reshape), and the usual off-by-one error and the lack of the assert caused the program to run for a looooooong time before I thought to interrupt it.
The two hardest problems in programming are naming things, garbage collection, and off-by-one errors. -- Raul Miller http://www.jsoftware.com/pipermail/programming/2013-January/031151.html On Thu, Dec 7, 2017 at 8:01 AM, Joe Bogner <[email protected]> wrote: > Beautiful and logical. Thanks > > I had to work though it to better understand it > > Find the position of the greatest number > Fill zeros up until that point > From that point, take the greatest number and spread it out as 1s > Take successive parts of the list (infixes) corresponding to the number of > buckets.. (leftover would fill to zero so it would have no impact) > Add up the parts to get the amount to add to each bucket > > > > > 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 > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
