Skip to content

Instantly share code, notes, and snippets.

@sordina
Created January 16, 2017 23:15
Show Gist options
  • Select an option

  • Save sordina/97284ce2d44ab0eb8bcd08883c9d174c to your computer and use it in GitHub Desktop.

Select an option

Save sordina/97284ce2d44ab0eb8bcd08883c9d174c to your computer and use it in GitHub Desktop.
primes :: [Integer]
primes = 2 : 3 : filter isPrime [4..]
isPrime :: Integer -> Bool
isPrime x = all (doesNotDivide x) (takeWhile (<= lb) primes)
where
lb = floor (sqrt (fromIntegral x :: Double))
doesNotDivide :: Integer -> Integer -> Bool
doesNotDivide x y = (x `mod` y) /= 0
fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
data BinaryTree x = Value x | Branch (BinaryTree x) (BinaryTree x)
deriving (Show)
prettyTree n (Value v) = putStrLn (replicate n ' ' ++ show v)
prettyTree n (Branch l r) = do
putStrLn (replicate n ' ' ++ "<l>")
prettyTree (n + 1) l
putStrLn (replicate n ' ' ++ "<r>")
prettyTree (n + 1) r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment