Skip to content

Instantly share code, notes, and snippets.

@stsatlantis
Last active December 2, 2017 22:13
Show Gist options
  • Save stsatlantis/bae30d7e283255b5a1f8903aca2564ab to your computer and use it in GitHub Desktop.
Save stsatlantis/bae30d7e283255b5a1f8903aca2564ab to your computer and use it in GitHub Desktop.
Advent of Code 2017 - Day2
def checkCorruptChecksum(_source: List[List[Int]]) = {
_source.map(
_.map(x => (x, x))
.reduceLeft((x, y) => (x._1 min y._1, x._2 max y._2)
)
).map { case (a, b) => b - a }
.sum
}
def advancedCheckCorruptChecksum(_source: List[List[Int]]) = {
_source.map(_.combinations(2).collect {
case a :: b :: _ if a % b == 0 => a / b
case a :: b :: _ if b % a == 0 => b / a
}.sum).sum
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment