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.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, ...
First time I've done Advent of Code, but here is my Haskell soloution for Day 3:
A bit of Go
Still going strong with COBOL
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 :)
I put my solution in a gist. It's only for the second part, but I think it's easy enough to adjust it back for the first.
That was quick! I'm just going to put that this one is in JavaScript for my future language-tallying self 😊 Thanks for sharing!
I'm always amazed by the main leader board. Some people seem to have solved the tasks in under five minutes. I can't even read it in that time 😁
Here is my Day 3 in Ruby
Hi,
In PHP again, for fun, I try to have the minimum of temporary variables.
Full size here : Advent Of Code - Day 3
Haskell
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:
Short Python solution
Completed my day 3 with a little help from comments here
Mine!
Python effort, short and simple and gives the right answer.
Hi,
Can you explain why "line = line + line" 7 times?
(Maybe i missed something in the question...)
10x :)
Hi Rabbi, you have a short string that repeats indefinitely. As you move right you quickly hit the end of the string. It was a very simple way to repeat the pattern otherwise you get an index out of range error when you exceed the original string length.
Its not very efficient as it repeats every line but it works in this instance. If you had to create longer strings you might want to refactor to check if you've hit end of string and only repeat then.
Dan
Great! That helped me understand my mistake (Thous that end of line leads to the next line) :)