On Wed, Dec 14, 2022 at 3:49 PM Jaume <greenni...@gmail.com> wrote: > The first days I tried, now I have less time and the problems are harder.
That does happen. I expect aoc day 24 to take me a few days to solve (unless it happens to be a problem I somehow have already put a lot of thought into). > I have to say that parsing the input sometimes is the hardest part for me > (with J). On day 11 I parsed it manually and created 7 sets of elements for > the real input, plus the 4 for the test. It took less time than trying to > create the parser. On day 7 both the input and the processing were too hard > for me (in J) so I had to resort to C#. I still can't think J enough and > lack some knowledge. I've been doing several implementations of these early puzzles. Day 11, in particular, I first solved with matrix representation the monkeys with a boxed list of the items each held, but then I rewrote it using an entirely different approach. The parsing looked something like this: day11=: {{ OP=: ,_7 {{13 :y`''}}@,\(}.~ 1+i.&'=');._2 y rplc ;:'old y' N=. _7]\<@".@([-.-.)&(":i.10);._2 y M=: ((3 5 4 >@{"1])-0,.0 0 >@{"1]) N L=. 3{.|:;2 ,.&.>/@{."1 N }} Here, OP was a gerund such that OP@.0 represented what monkey 0 would do to the "worry levels", OP@.1 represented monkey 1, and so on. Also, M represented, for each monkey: the divisor to check against, the "monkey offset" to add to the monkey id for the case where the worry level is not 0 modulo that divisor, and the "monkey offset to add to the monkey id for the case where the worry level is evenly divisible by the divisor. Here, I had decided that modulo addition (with the number of monkeys as the modulo) was a better fit than array indexing when determining the next monkey. The L value, here (the result of the verb I posted here has three rows and is conceptually the initial state of an "accumulator". The first two rows here correlate with each other, one column for each "item". current monkey id worry level The last row doesn't really match the those two rows -- it is not associated with items -- it's just padded with zeros to fit. It's the current inspection count for each monkey. --------- For day 7, my first implementation carefully constructed paths for each of the directories, but that was unnecessary work. A useful insight here is that each directory is visited only once. So the input represents a depth first tree traversal, and all you really need to do is distinguish cd .. from other cd invocations and extract the list of sizes (one size per line). > Even with that this year I'm quite happy with my results so far. Last time > I tried J was back in '19, and tried to do it with my mobile phone while > commuting. Too hard, too many things to write. And because I wasn't able to > parse the first intcode day I didn't continue after the next one appeared. Phones are fun, but frustrating. Anyways, it's great that you're getting something out of this. > I'm improving on several fronts. Learning more J day by day, sometimes in a > surprising fashion, like the day after I read about &: and thought "this is > probably a fringe mathematical construct, I will not use it" I used it for > counting the threes. Learning more how jqt works, like on day 11 that I > learned about ctrl+E. On day 13 I learned to debug (not as well as I'd > like) and changed my work style, so instead of working on jqt and copying > from time to time everything on a log file I write on the file and copy it > and F8 on jqt. I'd use the J extension for VScode, but it's not finding > ijconsole, probably because it's a SteamDeck, which has lots of things > locked down. It doesn't find dotnet either (and I have both). Huh... I haven't tried VScode, myself, and usually stick with jqt or jconsole. > It's a fun experience and the helpfulness from all the people here brings > even more joy. > > Thanks again everyone. Now back to cleaning past days' submissions. Thanks for sharing! -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm