Fix a bug where 'hgt' was not followed by cm|in
This commit is contained in:
@@ -24,15 +24,16 @@ class Day04(@Text val input: Input<String>) {
|
||||
|
||||
fun part1(): Int = entries.count { it.hasRequiredKeys() }
|
||||
|
||||
private fun Entry.hasValidValues(): Boolean {
|
||||
val (k, v) = this
|
||||
return when (k) {
|
||||
private fun Entry.hasValidValues() = let { (k, v) ->
|
||||
when (k) {
|
||||
"byr" -> v.toInt() in 1920..2002
|
||||
"iyr" -> v.toInt() in 2010..2020
|
||||
"eyr" -> v.toInt() in 2020..2030
|
||||
"hgt" ->
|
||||
if (v.endsWith("cm")) v.removeSuffix("cm").toInt() in 150..193
|
||||
else v.removeSuffix("in").toInt() in 59..76
|
||||
"hgt" -> when {
|
||||
v.endsWith("cm") -> v.removeSuffix("cm").toInt() in 150..193
|
||||
v.endsWith("in") -> v.removeSuffix("in").toInt() in 59..76
|
||||
else -> false
|
||||
}
|
||||
"hcl" -> v.matches("^#[0-9a-f]{6}$".toRegex())
|
||||
"ecl" -> v in arrayOf("amb", "blu", "brn", "gry", "grn", "hzl", "oth")
|
||||
"pid" -> v.matches("^[0-9]{9}$".toRegex())
|
||||
@@ -44,7 +45,7 @@ class Day04(@Text val input: Input<String>) {
|
||||
.asSequence()
|
||||
.filter { it.hasRequiredKeys() }
|
||||
.filter { it.all { it.hasValidValues() } }
|
||||
.count() - 1 // ???
|
||||
.count()
|
||||
}
|
||||
|
||||
fun main() = with(createDay<Day04>()) {
|
||||
|
||||
Reference in New Issue
Block a user