Skip to content

Instantly share code, notes, and snippets.

@tminard
Created December 5, 2019 15:16
Show Gist options
  • Save tminard/c361c031a133955d4a03a26731e9d039 to your computer and use it in GitHub Desktop.
Save tminard/c361c031a133955d4a03a26731e9d039 to your computer and use it in GitHub Desktop.
advent-of-code-2019
val candidates = Array.range(272091, 815432)
println("Initial digits: " + candidates.size)
val filteredAsc = candidates.map(_.toString.toArray).filter(a => a.sameElements(a.sortBy(_.toInt)))
println("Total digits with ascending order: " + filteredAsc.size)
val filteredDupOnly = filteredAsc.filter(a => a.toSet.size < a.size)
println("Total digits with at least 2 adjacent equal values: " + filteredDupOnly.size)
val filteredDoubleOnly = filteredDupOnly.map(_.groupBy(identity).view.mapValues(_.size)).filter(m => m.exists(_._2 == 2))
println("Total digits containing exactly two adjacent equal values: " + filteredDoubleOnly.size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment