Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Project Euler, problem 67 solution as coded at Czech Scala Enthusiasts' Scala soding dojo on Apr 9, 2013 Problem description:
package com.czechscala.blank
import io.Source
object Euler67 extends App {
def solve(triangle: List[IndexedSeq[Int]]): Int = {
val lowestRow = triangle.foldLeft(IndexedSeq[Int]()) { (upper, lower) =>
val lowerRow = lower.zipWithIndex
lowerRow map { case (value, idx) =>
val left = upper lift (idx) getOrElse 0
val right = upper lift (idx - 1) getOrElse 0
value + math.max(left, right)
def parseLine(line: String): IndexedSeq[Int] = line split " " map (_.toInt)
def parseLines(lines: List[String]): List[IndexedSeq[Int]] = lines map parseLine
def readFile(fileName: String): List[String] = Source.fromFile(fileName).getLines().toList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.