-- Advent of Code
---- Day 25: Let It Snow

module AOC2015.Day25 where

import Math.NumberTheory.Powers

{-
Right-to-left binary method
https://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method
-}

coord :: Int -> Int -> Int
coord n m = div (k*(k+1)) 2 + m
  where
    k = n + m

answers :: IO ()
answers = do
  putStrLn "-- Advent of Code 2015, Day 25 --"
  -- n and m are the input here
  let part1 = f 3010 3019
        where
          f n m =
            mod (powerMod 252533 c 33554393 * 20151125) 33554393
            where
              c = coord (n-1) (m-1)
  putStrLn $ "Part One: " ++ show part1
