Created
March 21, 2017 01:12
-
-
Save marcusmonteiro/3ee64e2ee1f772f665dde08df1cb3c62 to your computer and use it in GitHub Desktop.
Pisano Period in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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