Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fibonacci proof
{-- So, here we are fa-la-la, tra-la-la, and I pull from my bundle of tricks a math-ish problem. Counting is 'math'-...ish, isn't it? This is from @jammestanton who asks us to make the following observation about the Fibonacci numbers, which we found from our dear sweetie, Rosalind have to do with bunnies and what bunnies like to do. So, we have the Fibonacci number series: 1,1,2,3,5,8,... So let f n be the nth Fibonacci number so f 1 == 1, f 2 == 1, etc. --} f :: Integer -> Integer f 0 = 0 f 1 = 1 f n = (f $ n - 2) + (f $ n - 1) -- Now, let g n be the count of the Fibonacci numbers < n (so, g 3 == 3) g :: Integer -> Integer g n = foldl (\x _ -> x + 1) 0 . takeWhile (< n) $ map f [1..] -- NOW, let h n be the count of the number of g's that are < n h :: Integer -> Integer h n = foldl (\x _ -> x + 1) 0 . takeWhile (< n) $ map g [1..] -- James asks: What do you notice unique to Fibonacci numbers? main = print $ map f [1..10] == map h [1..10]
run
|
edit
|
history
|
help
0
first haskell program
My "tying the knot"
(Int,Int) -> Bool plot
Factors of a number, prime numbers
Cubed
haskell_exam
folder
Monoid and friends
Derive type class for parameterized data type
State