Skip to content

Instantly share code, notes, and snippets.

@bwbaugh
Last active November 12, 2015 23:57
Show Gist options
  • Save bwbaugh/41b523e3784421d6e25a to your computer and use it in GitHub Desktop.
Save bwbaugh/41b523e3784421d6e25a to your computer and use it in GitHub Desktop.
Visualize the parity of the sum of digits from numbers of the Fibonacci sequence. https://oeis.org/A004090
import Data.Char (digitToInt)
import System.IO
main :: IO ()
main = do
hSetBuffering stdout NoBuffering
putStrLn $ concatMap toFancy $ sumOfDigits fib
toFancy :: Integer -> String
toFancy x
| even x = "▓"
| otherwise = "░"
sumOfDigits :: [Integer] -> [Integer]
sumOfDigits = map (sum . map (toInteger . digitToInt) . show)
fib :: [Integer]
fib = 0 : 1 : zipWith (+) fib (tail fib)
@bwbaugh
Copy link
Author

bwbaugh commented Nov 12, 2015

take 50 $ sumOfDigits fib
[0,1,1,2,3,5,8,4,3,7,10,17,9,8,17,7,24,22,19,14,24,20,17,28,27,19,19,29,21,23,17,31,30,34,37,35,27,35,44,43,24,31,46,41,33,29,35,37,54,55]

putStrLn $ concatMap toFancy it
▓░░▓░░▓▓░░▓░░▓░░▓▓░▓▓▓░▓░░░░░░░░▓▓░░░░▓░▓░▓░░░░░▓░

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment