We're on to Day 3 now! I'm seeing a bunch of cool languages getting submitted, which is really fun. Let's get to the puzzle!
The Puzzle
In today’s puzzle, we're trying to toboggan down a foresty slope to get to the coast for our trip. But trees aren't conducive to safe sledding, so we're checking our options carefully before starting. 2-D grids are a staple of Advent of Codeses past, and we've seen things dealing with rational slopes too. But it'll be interesting seeing how you decide to sled down these particular rational slopes. 😉
The Leaderboards
As always, this is the spot where I’ll plug any leaderboard codes shared from the community.
Ryan's Leaderboard: 224198-25048a19
If you want to generate your own leaderboard and signal boost it a little bit, send it to me either in a DEV message or in a comment on one of these posts and I'll add it to the list above.
Yesterday’s Languages
Updated 03:06PM 12/12/2020 PST.
Language | Count |
---|---|
Python | 5 |
Ruby | 3 |
Rust | 3 |
JavaScript | 2 |
Raku | 1 |
COBOL | 1 |
PHP | 1 |
Elixir | 1 |
C | 1 |
Merry Coding!
Top comments (39)
Rust again
Rustaceans gonna stick together 🦀:
As always, also available on Github.
The
enum
implementation for your input is cool; I wouldn't have thought of that.First time I've done Advent of Code, but here is my Haskell soloution for Day 3:
Rust using lots of iterators and generators. I'm trying to learn the standard library properly now.
Nice! Didn't know about
product()
; will have to keep that in a pocket.I like that your solution allows for an arbitrary starting point, rather than always just (0,0).
One thing I've learned about AoC - try not to bake in any assumptions in part 1!
Maybe this'll be our repeating problem (like the opcodes last year)... Different starting points, different types of obstacles in the snow, terrain to avoid, ...
A bit of Go
typical December in Europe
There is my solution, Elixir as always. I'll switch to Golang/PHP when I get stuck.
Day 3, part 1:
Day 3 part 2:
What's your experience guys? Better to keep both parts in one class/module / whatever?
I typically keep them in the same file in different functions, since work from part 1 is often shared to part 2, (like today), but every so often, he throws a curveball and part 2 ends up being a total rethink, and then it may be nicer to have more separation. It probably doesn’t matter a ton :)
Still going strong with COBOL
Here is my Day 3 in Ruby
OK! Here's my solution. I wasn't sure how managing the 2D grid was going to go in C since I've historically struggled with them in Rust. But it went pretty easy and ran super fast, so I'm very happy with it :)
I had trouble for a minute because my code was skipping slots in my array because of the newline characters in the input. Once I stopped incrementing my index when I saw a newline, it shaped right up!
Day3.h:
Day3.c:
Additional code to parsing.h:
Aaaand the implementation:
Completed my day 3 with a little help from comments here
Short Python solution