Day 12 solution thread
# advent-of-code
a
Day 12 solution thread
The waypoint rotation got me for a while
a
Solved by simple fold over the Instructions using a different data class for Part1 & Part2 Most complicated bit was turning the waypoint in Part 2
e
https://github.com/ephemient/aoc2020/blob/main/kt/src/main/kotlin/io/github/ephemient/aoc2020/Day12.kt eh, turning the waypoint in part 2 is the exact same code as turning the direction in part 1
I should probably share more code between parts 1 and 2 - the only difference is whether N/E/S/W affect the position or the direction/waypoint - may do that later
e
@ephemient It's the same for me as well. Just realized
R
and
L
are the same operations in both parts. But for now, my solution looks like this: https://github.com/edgars-supe/advent-of-code/blob/master/src/main/kotlin/lv/esupe/aoc/year2020/Day12.kt
e
unified now. instead of doing anything fancy by dispatching moves by polymorphism, I just split it out with
Copy code
private fun solve(waypoints: Boolean): Int
 fun part1(): Int = solve(false)
fun part2(): Int = solve(true)
j
finally the opportunity to use operators overloading 🙂
r
Ever since someone asked me if my code was satire I was a bit ashamed of posting here, but I’m decently proud of my code today: https://github.com/renatomrcosta/adventofcode/blob/main/src/main/kotlin/aoc2020/day12/pt2/day12.kt
👏 1
j
Never be ashamed of your AoC code. We're doing it for fun and to learn something. You're going in the right direction, and even if your code is still a bit... uh... baroque 🙂, there is nothing wrong from being proud of it 🙂
n
@renatomrcosta I'm sorry, that was me, that wasn't my intention.
IT was, believe it or not, asked in good faith, but since it's too hard to genuinely communicate that over this medium, I should have kept it to myself
My solution. Did a fair bit more of modelling of the data compared to previous days, I think it helps keep repetition to a minimum later though:
💪 1
r
Don't worry @Nir no harm, no foul. Btw, your day 10 was exquisite, really dope solution
n
Aww thanks, that's too kind. Btw, your solution for today is very good! Took a quick skim.
r
like I said, first time in 12 days I’m proud haha. Even a broken clock is right twice a day
fingers crossed the streak keeps up
(honestly, since then I’ve been streamlining a lot, and it has really helped a ton. So the feedback was invaluable, after all)
n
Yeah I did not mean it in a negative way. I know it's common for programmers esp from Java to be trained/used to this school of thought where classes, inheritance, etc are used super heavily, but also common for people to make jokes about it. I do think this code is nice because it's using objects and such but in a reasonable way; it looks like reasonable code scaled down to a toy problem. To me personally, the previous code felt over the top a bit in that "Java" sense, but again I did not mean to antagonize or discourage you, especially never the latter. Glad you are still posting your solutions, you should
I'm simplifying it (like south is always north(-value))
kind of the same for left and right
oh I see a typo
(my floor mod had 360 instead of 4
it was still working by chance because all the rotations were given in a nice range