Skip to content

Instantly share code, notes, and snippets.

@AntonFagerberg
Last active December 3, 2015 19:47
Show Gist options
  • Save AntonFagerberg/56c782b8434232ae347e to your computer and use it in GitHub Desktop.
Save AntonFagerberg/56c782b8434232ae347e to your computer and use it in GitHub Desktop.
Advent code
"2x2x4\n1x1x10".split("\n").map(_.split("x").map(_.toInt).sorted).map { case Array(a,b,c) => a*b*3 + (a+b)*c*2 }.sum
"2x2x4\n1x1x10".split("\n").map(_.split("x").map(_.toInt).sorted).map { case Array(a,b,c) => (a+b)*2 + a*b*c }.sum
"^>v<".
map {
case '^' => (0, 1)
case 'v' => (0, -1)
case '<' => (1, 0)
case '>' => (-1, 0)
}.
scanLeft((0, 0)) { case ((xx, yy), (x, y)) => (x + xx, y + yy) }.
distinct.
length
"^>v<".
map {
case '^' => (0, 1)
case 'v' => (0, -1)
case '<' => (1, 0)
case '>' => (-1, 0)
}.
zipWithIndex.
scanLeft(((0,0), (0,0))) {
case (((xx, yy), z), ((x, y), i)) if i % 2 == 0 => ((x + xx, y + yy), z)
case ((z, (xx, yy)), ((x, y), _)) => (z, (x + xx, y + yy))
}.
flatMap { case (x, y) => List(x, y) }.
distinct.
length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment