{-# Language MagicHash, UnboxedSums, QuasiQuotes #-}
module Main where
import Advent.Format (format)
import GHC.Natural (Natural)
import GHC.Num.Integer (integerPowMod#)
main :: IO ()
IO ()
main =
do (Integer
row,Integer
col) <- [format|2015 25 To continue, please consult the code grid in the manual. Enter the code at row %lu, column %lu.%n|]
Integer -> IO ()
forall a. Show a => a -> IO ()
print (Integer -> Integer -> Integer
code Integer
row Integer
col)
code ::
Integer ->
Integer ->
Integer
code :: Integer -> Integer -> Integer
code Integer
row Integer
col
= Integer
20151125
Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer -> Integer -> Natural -> Integer
powModInteger Integer
252533 (Integer -> Integer -> Integer
cell (Integer
rowInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
-Integer
1) (Integer
colInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
-Integer
1)) Natural
33554393
Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`mod` Integer
33554393
powModInteger :: Integer -> Integer -> Natural -> Integer
powModInteger :: Integer -> Integer -> Natural -> Integer
powModInteger Integer
x Integer
y Natural
m =
case Integer -> Integer -> Natural -> (# Natural | () #)
integerPowMod# Integer
x Integer
y Natural
m of
(# Natural
x | #) -> Natural -> Integer
forall a. Integral a => a -> Integer
toInteger Natural
x
(# | ()
_ #) -> String -> Integer
forall a. HasCallStack => String -> a
error String
"powModInteger: bad argument"
cell ::
Integer ->
Integer ->
Integer
cell :: Integer -> Integer -> Integer
cell Integer
r Integer
c = Integer -> Integer
sum1N (Integer
rInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+Integer
c) Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
c
sum1N :: Integer -> Integer
sum1N :: Integer -> Integer
sum1N Integer
n = Integer
nInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*(Integer
nInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+Integer
1)Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`quot`Integer
2