Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
here is my solution for reference https://github.com/aaronallen8455/aoc2020/blob/main/src/TwentyFive.hs.
You don't have to implement expMod yourself, because multiplication under a modulus has a semigroup/monoidal structure, and stimes handles that for you. I'm a little fuzzy on a type-correct way to do it that's flexible on the modulus, since really the modulus should be a type parameter rather than a value parameter to ensure it's the same across all multiplications. But for a fixed modulus, as in this puzzle, it's quite easy. My solution looks like:
Video walkthrough and code repo.
My solution: https://github.com/pwm/aoc2020/blob/master/src/AoC/Days/Day25.hs
I didn't use the "discrete logarithm" concept and just brute forced it, but my code takes a few seconds to run (and is also much more beginner Haskell-y): https://github.com/derifatives/explorations/blob/master/advent_of_code/2020/day_25.hs
I also solved this in a similarly lazy (heh) way and while it's not very fast it's acceptable.
Can anyone understand how hack() works here: https://github.com/glguy/advent2020/blob/master/execs/Day25.hs ?