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 10:13

>>21
point-free
You do realize point-free is optional, right? And people rarely use it except for composing a bunch of functions to pass the result to a HOF.

funny precedence rules
If precedence confuses you, then you really are a moron.

map and reduce shit
That's a optimization issue. You're gonna judge a language based on a fixable, temporary, compiler specific, optimization issue? Wow, that's not moronic at all.

mixing monad types
Why, you think it's hard? Using transformers is trivial, but if you're put off by the nesting, just write yourself a new monad. Oh, wait, you can't, you're a moron. Sorry, that was insensitive of me.

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