Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Project Euler problem 18/67 solver in Haskell

Name: Anonymous 2009-10-22 19:51


maximumPath :: [[Int]] -> Int
maximumPath tl = head $ foldl (flip reduce) (head rtl) (tail rtl)
  where rtl = reverse tl
        reduce [] b = []
        reduce a [] = []
        reduce (a:as) (b:c:bs) = (a + max b c) : reduce as (c:bs)
        reduce (a:as) [b] = [a + b]


To solve 67 (which is the more interesting one),


trif <- readFile "triangle.txt"
let answer = maximumPath $ map (\l -> map read l) (map words (lines trif))

Name: Anonymous 2009-10-25 9:53

>>19

Maybe point-free style is succint. Except that it resists any attempts toward refactoring. Take a point-free-style code and it has to be rewritten with every tiny modification. Then add to that funny precedence rules ("otherwise currying won't work") and it's Perl sans sigils.

Oh, and when you map and reduce shit, you have to pray to the deforestator that it won't cons. Because there's no fucking guarantee. Deforestator has some hardcoded operators built in and that's it. Use anything else and suddenly the code conses like there's no tomorrow.

Also, good luck mixing monad types. Enjoy your AIDS.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List