Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import scala.io.Source
object Advent {
def main(args: Array[String]): Unit = {
val data = Source.fromFile("data/day1.txt").getLines.map(_.toInt).toList
println(f"Part 1: ${data.sum}")
/* Can someone help me get this second part a littler more Scala-like (more functional, less procedural)? Please let me know! */
var seen: Set[Int] = Set()
var dup: Option[Int] = None
var start: Int = 0
while (dup.isEmpty) {
val scanned = data.scanLeft(start)(_ + _).drop(1)
dup = scanned.find(seen.contains(_))
seen = seen ++ scanned
start = scanned.last
}
println(f"Part 2: ${dup.get}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.