I’m on mobile today, so putting this together is a little later and a little more interesting today. But here you go! Happy day 12!
The Puzzle
In today’s puzzle, we're not just sitting on the ferry. We get to drive it! You’re following directions from the navigation system to move the boat around. How is the boat strafing sideways? I don’t know. You’re the boat driver!
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:04PM 12/12/2020 PST.
Language | Count |
---|---|
Ruby | 2 |
Haskell | 2 |
JavaScript | 2 |
COBOL | 1 |
Go | 1 |
Cpp | 1 |
C | 1 |
Rust | 1 |
Merry Coding!
Top comments (17)
Still insisting on proper modelling, unit tests and real parsers over string splitting and regex.
I have to ask - why avoid regex use? Seems just another tool in the toolbox.
It is another tool in the box, and sometimes even the right tool. But regex is a sub-optimal general solution to what is often a quite specific task. One of my passions in programming is to show that real parsers are almost always better in the long run, and they're not hard to write.
Here's a recording of a talk I did at the Edinburgh Kotlin user's group last year on the subject: vimeo.com/393132096
Part 1 Python
New to coding and behind in the calendar but this one looked easy overall.
not sure how to get syntax highlighting to show here
Part 2
I need to refactor this and function it out
Nice! I like how you folded the absolute directions and the forward commands into one action with checks on the current direction. Look into the
%
(modulo) operator for handling the circular arithmetic around the rotation additions - in short(dir + num) % 360
for right turns and(dir + 360 - num) % 360
for left.So many
match
statements.COBOL (part 2 on GitHub)
Not too bad! I had an issue with the rotation in part 2, and I ended up writing so. many. tests. to find it. Which totally payed off!
Day12.h:
Day12.c:
There are (at least) two ways to "model" the solution: polar coordinates or vector/gonio math. Here is a Ruby OOP solution using the latter:
Got through this one fairly quickly (problem sat well with how my mind works, I guess).
As always, on Github.
Warning, lots of code today! I've been making an effort to model my solutions in ways that do not require special branching, or separate solutions for the 2 parts. Today was a fun one, and I think I came up with a good design, even if it's a little verbose!
At this point I think my enterprise development roots are showing. I've got inheritance, interfaces, strategies, factories, and even a DI container in my overall 2020 codebase 🤣
Part1
Part 2
FerryBase
Ferry (Part1's Implementation)
WaypointFerry (Part2's Implementation)
Part 1 and 2 JS solution, toggle
part2
to true or false depending on your needs!Here it is minified (498 characters, not tweet-sized 🙄):
I'm gonna post the 2 parts separately, as it looks like it's gonna be easier to edit the code than to support both parts with the same module.
here's part 1:
Part 2: