Last active
December 2, 2017 22:13
-
-
Save stsatlantis/bae30d7e283255b5a1f8903aca2564ab to your computer and use it in GitHub Desktop.
Advent of Code 2017 - Day2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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