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 P...
For further actions, you may consider blocking this person and/or reporting abuse
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:
Another javascript master piece: this gist.
Happy to use the javascript value swap shortcut in this one:
Fun today, although solved part 1 before going out this morning, only to realise I needed slighty different function for part 2 :-) In the end just went with 2, mostly same, functions, as did not have the will power to generalize!
It's nice now that I'm starting to have a litlte library of "AOC" functions that I can call upon.
My JavaScript walkthrough: