Today's tasks felt much easier than yesterday's, but maybe it was because they were closer to what I used to do at $job - 2.
Let's recursively parse a tree from a sequence of integers! Meaning of each number depends on its position in the sequence and on the meaning of the other numbers...
Top comments (13)
Kinda happy with this one!
Woah, that recursive constructor for
Treeis really clever!
I considered building an object and then processing it after the fact, but decided to process it as I parsed it...I regretted that when I saw part 2 though 😅
I was missing parser combinators so came back and did day 8 again.
It was initially much more dense but I tried to break it up to make it easier to follow. It's not the One True Way of parsing for nothing you know!
Recursion, or: finally a chance to use my degree. Did I need to actually build the tree in Part 2? Probably not, but it made it easier to organize the data and actually do the recursion, so ¯_(ツ)_/¯
Here is my Golang solution for today's problem. It was more easy for me to solve today, but made me learn to use pointers in Golang to consume the input string. I don't think this is necessarily the best way to use pointers, but I liked the simplicity in this case.
Agreed, today's was much simpler. My Kotlin:
Here is my Python Solution:
And here are my Perl solutions:
@choroba , thanks again for putting this post up! Sorry for not getting it out on time yesterday.
I liked this challenge! Something about this one just worked out for me and I didn't have to wrestle with it very much. Also, this was my first time defining a recursive data structure in Rust, and I didn't have any issues -- hopefully I did it the right way!
For part 2, I didn't have to change the data structure at all, I just created the
valuefunction to describe how the new thing was calculated.
This is my js solution using recursive functions
I liked this challenge a lot! It felt a lot more straightforward than the other problems.
The code came out extremely succinct, too, which is always nice. IMO it's quite readable:
Part 2 looks almost identical to part 1, but with an extra branch in the middle.