Created
December 5, 2019 15:16
-
-
Save tminard/c361c031a133955d4a03a26731e9d039 to your computer and use it in GitHub Desktop.
advent-of-code-2019
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
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