Skip to content

Instantly share code, notes, and snippets.

@ashiato45
Created April 5, 2014 14:27
Show Gist options
  • Save ashiato45/9992680 to your computer and use it in GitHub Desktop.
Save ashiato45/9992680 to your computer and use it in GitHub Desktop.
import Control.Monad
import Data.Map
import Data.Maybe
newtype Triplet = Triplet (Integer, Integer, Integer)
applyMany :: Integer -> (a -> a) -> a -> a
applyMany 0 f a = a
applyMany n f a = 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