Learning Dart by working my way through Advent of Code 2016 (in March 2022).
Installed Dart 2.16.1 via homebrew
.
- VSCode:
F5
- Terminal
dart run [path-to-file]
- Dart is mostly OOP with a few functional constructs like
map
- .removeWhere is like .filter
- can use LineSplitter to separate new line characters across all OS
- cascade notation can be used to chain together operations on a single object
- how to read in a file?
- configure vs code debugger
- is there a linter?
- final vs const
- clean up how we approach this problem to make it easy to switch between test cases and actual dataset
- add assert statement for Day 1
- should we start approaching everything with an OOP mindset?
- very easy to set up equality b/w objects: https://work.j832.com/2014/05/equality-and-dart.html
- how lightweight are Dart classes?
- Found a Day 6 solution that features Multiset and fold
- if this patterns comes up again; learn what's going on there
Comparing solutions against https://github.com/julemand101/AdventOfCode2016/tree/master/bin
Fairly straightforward problem. This is my first time using Dart so I have been looking up modules and syntax as I worked through the problem. Dart does not have native Tuple support; tried a Google implementation but it was not right.
The .toString
method does make life easy if we have to hash small arrays (which we treat as tuples) inside of a Set. TIL: We can use the Point class to represent 2D positions.
Used Point
and Map
to build a key-value data structure for all the values in the Number Pad. Still trying to find a good way to organize Dart scripts. I think my template will be more helpful tomorrow than it was today.
Had to reach into the RegEx toolbox today to parse the puzzle data. Dart arrow functions are used to define a single expression. When using functional programming functions (map
, reduce
, and forEach
), we have to use the regular function syntax to pass in functions.
Converting my input data into Objects and used straight forward OOP to solve this problem. Need to do some research into how lightweight Dart classes are, but I can see this being a powerful way to handle JSON-like data.
I can start to see how Dart is a powerful language -- it's syntax gets out of the way letting you get classes up and running really quickly.
- Regex non-capturing groups start with
?:
final
keyword in Dart is similar to how we useconst
in ES6 and TS- Dart OOP -- creating classes, getters, setters, etc
Today was a brute-force problem that used the MD5 algorithm (via Dart's crypto package) to calculate a hash. It took around 50 seconds for each of my solutions to run.
Once I learn Flutter, this will be a fun one to animate.
A simple counting puzzle. 2016 is pretty straightforward so far.
Lots of text manipulation in this puzzle. Wrote a function to process each line and then I solved this problem in a fairly functional way.
This was took a bit longer than expected. Used a very Object-Oriented solution, but got wires mixed up with rows / columns vs y / x. Really liking Dart; can't seem to find anything about naming function parameters... but I need to do a bit more research.