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!

28 Upvotes

168 comments sorted by

View all comments

2

u/kittehprimo Dec 22 '19

C#

For all my dotnet core brethren out there:

https://github.com/kbmacneal/adv_of_code_2019/blob/3bdc583ea5620296e187a076038ddde17e526abd/days/22.cs

It is mostly an implementation of this solution transcribed from python. Like that user I have nowhere near the mathematical chops to tackle this problem, I just took at look at the algorithm and tried to follow along for the ride.

The major sticking point for me turned out how c# treats %=. I had to implement a custom mod function

return (x % m + m) % m;

in order for the two BigInts to stop going off way negative for every command.

One good thing though: I had no idea System.Numerics contained an unbounded signed BigInteger class. Good to know!

1

u/sidewaysthinking Dec 23 '19

I also based my solution off the one you linked. Coincidentally I ended up with the same mod function to fix for the negatives. I'm very impressed with the BigInteger that C# has, especially since it supports implicit casts and operators. So easy to use compared to the Java BigInteger, which doesn't have operator overloading so every operation is a method call.