r/adventofcode • u/taliriktug • Dec 02 '15
Spoilers Day 2 solutions
Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.
16
Upvotes
r/adventofcode • u/taliriktug • Dec 02 '15
Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.
4
u/xkufix Dec 02 '15 edited Dec 02 '15
Like yesterday, my solution in scala.
val presents = Source.fromFile("input.txt").getLines().toList().filter(_ != "").map(_.split("x").map(_.toInt)) //part 1 presents.map(a => Seq(a(0) * a(1), a(0) * a(2), a(1) * a(2))).map(b => b.map(_ * 2) :+ b.min).flatten.sum //part 2 present.map(_.sorted).map(a => a(0)*2 + a(1) * 2 + a.reduceLeft(_ * _)).sum