Created
April 5, 2015 20:02
-
-
Save tfausak/1300a884f8097b69f06c to your computer and use it in GitHub Desktop.
Which one of these Haskell programs would you rather read and maintain?
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
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 |
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
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