Created
December 5, 2018 16:33
-
-
Save jonathan-ostrander/5a3381dee2724024b99e1a9c17e3a5e9 to your computer and use it in GitHub Desktop.
Advent of Code 2018 Day 5
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
// https://adventofcode.com/2018/day/5 | |
object Problem5 extends Base("input5.txt") { | |
def reactPolymer(string: String): String = string.foldLeft[List[Char]](Nil) { | |
case (h :: t, char) if h != char && h.toUpper == char.toUpper => t | |
case (acc, char) => char :: acc | |
}.mkString | |
val input = lines.head | |
val reduced = reactPolymer(input) | |
println(s"Part 1: ${reduced.length}") | |
val smallest = ('a'.toInt to 'z'.toInt).map { charInt => | |
val char = charInt.toChar | |
reactPolymer(input.filter(_.toLower != char)).length | |
}.min | |
println(s"Part 2: $smallest") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment