lluque

AoC day 3

Dec 28th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.46 KB | None | 0 0
  1. import scala.io.Source
  2.  
  3. object day3 extends App {
  4.  
  5.   def isValid(t: Seq[Int]): Boolean = {
  6.     val (a, b) = t.sorted(Ordering[Int].reverse).splitAt(1)
  7.     a.head < b.foldLeft(0)(_+_)
  8.   }
  9.  
  10.   val triangles = Source.fromFile("day3.txt").getLines.toList map (l => l.trim split " +" map (x => x.toInt))
  11.   println(triangles.count(isValid(_)))
  12.   val triangles2 = triangles.transpose.map(c => c.grouped(3).toList).flatten
  13.   println(triangles2.count(isValid(_)))
  14.  
  15. }
Advertisement
Add Comment
Please, Sign In to add comment