Skip to content

Instantly share code, notes, and snippets.

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