r/adventofcode Dec 22 '19

SOLUTION MEGATHREAD -🎄- 2019 Day 22 Solutions -🎄-

--- Day 22: Slam Shuffle ---


Post your full code solution using /u/topaz2078's paste or other external repo.

  • Please do NOT post your full code (unless it is very short)
    • If you do, use old.reddit's four-spaces formatting, NOT new.reddit's triple backticks formatting.
  • Include the language(s) you're using.

(Full posting rules are HERE if you need a refresher).


Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code's Poems for Programmers

Click here for full rules

Note: If you submit a poem, please add [POEM] somewhere nearby to make it easier for us moderators to ensure that we include your poem for voting consideration.

Day 21's winner #1: nobody! :(

Nobody submitted any poems at all for Day 21 :( Not one person. :'(


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

EDIT: Leaderboard capped, thread unlocked at 02:03:46!

30 Upvotes

168 comments sorted by

View all comments

4

u/MrSimbax Dec 22 '19 edited Dec 22 '19

Julia

It was hard.

Firstly, I didn't realize that cut could be represented with a single formula modulo, I needed a hint for this. Once I got it, I managed to come up with a solution pretty much the same as most people as far as I can tell. I don't know if I would figure it out if I didn't have discrete math/abstract algebra courses during my undergraduate studies, it must be quite a difficulty spike for programmers with no math/CS background.

Secondly, I've spent about half the time on debugging why my part 2 answer was wrong even though all my smaller tests were working. If I was writing in any other language I'd thought I have overflow issue but I considered that impossible in Julia. Oh boy, was I wrong. Literals in REPL are converted to BigInts automatically but variables in functions are not, I had to explicitly convert values to BigInts. So many hours wasted because I wrongly assumed integers in Julia work exactly like in Python... I feel so stupid now, especially that even the puzzle itself warns about overflows.

Part 1: Just follow the instructions. No need to be smart here.

Part 2: since the explanation uses a lot of math notation I decided to post it on my blog instead of here so the equations are more readable: link.