Skip to content

Instantly share code, notes, and snippets.

@dbyrne
dbyrne / gist:874621
Created March 17, 2011 16:27
Project Euler #18 & #67 - Haskell
maxPath (x:y:xs) = maxPath (z:xs)
where z = zipWith (+) (zipWith max x (tail x)) y
maxPath [[x]] = x
convert = map (map read . words)
prob67 = show . maxPath . reverse . convert . lines
main = readFile "triangle.txt" >>= putStrLn . prob67
@dbyrne
dbyrne / gist:430074
Created June 8, 2010 14:14
Project Euler #18 & #67 - Clojure
(with-test
(defn maximal-path [tree-file]
(with-open [rdr (BufferedReader. (FileReader. tree-file))]
(let [lines (reverse
(map
(fn [x]
(map #(Integer. %) (re-seq #"\d+" x)))
(line-seq rdr)))]
(first
(reduce
@dbyrne
dbyrne / gist:424780
Created June 4, 2010 01:25
Project Euler #2 - Ruby
fibs = Fiber.new do
x1, x2 = 1, 2
loop do
Fiber.yield x1
x1, x2 = x2, x2+x1
end
end
sum = 0
begin