Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.io.Source
- object day3 extends App {
- def isValid(t: Seq[Int]): Boolean = {
- val (a, b) = t.sorted(Ordering[Int].reverse).splitAt(1)
- a.head < b.foldLeft(0)(_+_)
- }
- val triangles = Source.fromFile("day3.txt").getLines.toList map (l => l.trim split " +" map (x => x.toInt))
- println(triangles.count(isValid(_)))
- val triangles2 = triangles.transpose.map(c => c.grouped(3).toList).flatten
- println(triangles2.count(isValid(_)))
- }
Advertisement
Add Comment
Please, Sign In to add comment