Skip to content

Instantly share code, notes, and snippets.

@tfausak
Created April 5, 2015 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfausak/1300a884f8097b69f06c to your computer and use it in GitHub Desktop.
Save tfausak/1300a884f8097b69f06c to your computer and use it in GitHub Desktop.
Which one of these Haskell programs would you rather read and maintain?
module Euler8 where -- http://projecteuler.net/problem=8
import Data.Char (digitToInt, isDigit)
import Data.List (tails)
main :: IO ()
main = getContents >>= print . euler8
euler8 :: String -> Int
euler8
= maximum
. map product
. takes 13
. map digitToInt
. filter isDigit
takes :: Int -> [a] -> [[a]]
takes n = map (take n) . tails
module Euler8Flow where -- http://projecteuler.net/problem=8
import Flow -- http://hackage.haskell.org/package/flow
import Data.Char (digitToInt, isDigit)
import Data.List (tails)
main :: IO ()
main = do
input <- getContents
let output = euler8 input
print output
euler8 :: String -> Int
euler8 string = string
|> filter isDigit
|> map digitToInt
|> takes 13
|> map product
|> maximum
takes :: Int -> [a] -> [[a]]
takes size list = list
|> tails
|> map (take size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment