Skip to content

Instantly share code, notes, and snippets.

@stsatlantis
Last active December 2, 2017 11:16
Show Gist options
  • Save stsatlantis/9a09337e9da59784461d5f1bce368b22 to your computer and use it in GitHub Desktop.
Save stsatlantis/9a09337e9da59784461d5f1bce368b22 to your computer and use it in GitHub Desktop.
Advent of Code 2017 - Day1
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