Skip to content

Instantly share code, notes, and snippets.

@marcusmonteiro
Created March 21, 2017 01:12
Show Gist options
  • Save marcusmonteiro/3ee64e2ee1f772f665dde08df1cb3c62 to your computer and use it in GitHub Desktop.
Save marcusmonteiro/3ee64e2ee1f772f665dde08df1cb3c62 to your computer and use it in GitHub Desktop.
Pisano Period in Haskell
-- https://en.wikipedia.org/wiki/Pisano_period
fibs :: [Integer]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
pisanoPeriod :: Integer -> Int
pisanoPeriod m = length $ 0 : 1 : helper (drop 2 fibs)
where
helper (x:y:xs)=
if a == 0 && b == 1
then []
else a : helper (y:xs)
where
a = x `mod` m
b = y `mod` m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment