Skip to content

Instantly share code, notes, and snippets.

@ashiato45
Created April 5, 2014 15:22
Show Gist options
  • Save ashiato45/9993353 to your computer and use it in GitHub Desktop.
Save ashiato45/9993353 to your computer and use it in GitHub Desktop.
import Control.Monad
import Data.Map
import Data.Maybe
data Triplet = Triplet !(Integer, Integer, Integer)
applyMany :: Integer -> (a -> a) -> a -> a
applyMany 0 f a = a
applyMany n f a = a `seq` applyMany (n - 1) f (f a)
f :: Triplet -> Triplet
f (Triplet (a, b, c)) = Triplet (((a + b + c) `mod` 10007), a, b)
h :: Integer -> Integer
h 1 = 0
h 2 = 0
h 3 = 1
h n = let (Triplet (a, b, c)) = applyMany (n - 3) f (Triplet (1, 0, 0))
in a
main = do
n <- liftM (read :: String -> Integer) getLine
putStrLn $ show $ h n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment