Last active
December 2, 2017 11:16
-
-
Save stsatlantis/9a09337e9da59784461d5f1bce368b22 to your computer and use it in GitHub Desktop.
Advent of Code 2017 - Day1
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 simpleCaptcha(_source: String) = { | |
(_source + _source.head).map(_.asDigit).sliding(2).collect { case Seq(a, b) if a == b => a }.sum | |
} | |
def advancedCaptcha(_source: String) = { | |
val size = _source.length / 2 | |
val (firstHalf, lastHalf) = _source.map(_.asDigit).splitAt(size) | |
firstHalf.zip(lastHalf).collect { case (e1, e2) if e1 == e2 => e1 }.sum * 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment