Learning Dart by working my way through Advent of Code 2023.
While the company I work for uses Dart / Flutter, it's not something I do on a regular basis as I'm a backend developer. I spent some time before this job practicing Dart with Advent of Code and used that code to help me get this done.
I definitely hacked together a solution to get things out the door. Totally okay with it for now, its good to get re-familiar with types.
This was more about reading the data into a data structure I could work with easily. Think I did a pretty good job as the second part flowed easily from my part 1.
Used an object-oriented approach to set up the problem and then used a functional style approach to solve each of the methods. There were some edges that I didn't think about, but after a while I realized I had to track clusters separately since the part numbers repeat.
Found a great article that showed me how to overload operators in Dart.
Today was easy. Feels like I'm going back to a lot of the OOP principles that I'm comfortable with in Dart. I should start looking at other people's solutions to make sure I'm doing things in a way that makes sense.
I skipped this day initially since it sounded confusing when I read it at midnight. Came back to it on Day 10 -- part 1 was simple, but part 2 required a trick. Took some time to think through intersections of ranges (after getting a hint from the Chicago Python Slack). I feel like I re-write the same code every year as there is a problem like this every single year.
I brute-forced this one. Focused a lot more on writing functional Dart than I did thinking of a smart way to solve the problem, i.e. solving quadratic functions. Definitely learned a bit more about how to work in Dart which is good since I need to get a PR into our Flutter repo in the next few days.
ChatGPT was helpful in learning about more Dart features like Comparable and asMap
.
This was a fairly easy puzzle. I'm sure I could have done it in a much better way, but I'm fairly happy with how readable my code is. Dart is a fun language to work with.
TIL:
- Comparable interface
asMap
returns a MapEntry element has akey
and avalue
attribute
ChatGPT was helpful in generating functions to replicate itertools.chain
and calculate lcm
for a list of numbers.
A variant of this puzzle has been done before so it wasn't as bad if I hadn't done it in previous years. Did learn a bit about how async
works in Dart... not really useful for AoC but definitely useful for work.
ChatGPT was helpful in learning more about Dart.
Part 1 felt recursive and that definitely did work. Had some tricky parts, but nothing that I couldn't fix with a bit of debugging. Part 2 was the easiest part 2 in a long time -- maybe it was the language I used, but I just reversed the list and ran the same recursive solution and got the answer.
TIL:
- if your map has
null
and you filter thenull
out, Dart doesn't understand so you need to.cast<int>()
to make types work every
andany
are the ways to check a conditional against all / any of the values in a list