From f1c9e97ffbb9ab25c8d0a1f6bcddebc7c7b24b18 Mon Sep 17 00:00:00 2001 From: Stephan Linkel <251381+norganos@users.noreply.github.com> Date: Tue, 19 Dec 2023 10:10:34 +0100 Subject: [PATCH] day 18 and 19, as well as empty files for days 20-25 --- src/main/kotlin/de/linkel/aoc/Day19.kt | 47 ++-------------------- src/test/kotlin/de/linkel/aoc/Day19Test.kt | 12 +++--- 2 files changed, 9 insertions(+), 50 deletions(-) diff --git a/src/main/kotlin/de/linkel/aoc/Day19.kt b/src/main/kotlin/de/linkel/aoc/Day19.kt index e4f27b3..4c9e144 100644 --- a/src/main/kotlin/de/linkel/aoc/Day19.kt +++ b/src/main/kotlin/de/linkel/aoc/Day19.kt @@ -4,10 +4,9 @@ import de.linkel.aoc.base.AbstractLinesAdventDay import de.linkel.aoc.base.QuizPart import de.linkel.aoc.utils.iterables.intersect import jakarta.inject.Singleton -import java.math.BigInteger @Singleton -class Day19: AbstractLinesAdventDay() { +class Day19: AbstractLinesAdventDay() { override val day = 19 enum class Op(val char: Char, val lambda: (value: Int, threshold: Int) -> Boolean) { @@ -50,7 +49,7 @@ class Day19: AbstractLinesAdventDay() { } } - override fun process(part: QuizPart, lines: Sequence): BigInteger { + override fun process(part: QuizPart, lines: Sequence): Long { val iterator = lines.iterator() val rulePattern = Regex("([xmas])([<>])([0-9]+):([a-zAR]+)") val workflows = iterator @@ -84,50 +83,12 @@ class Day19: AbstractLinesAdventDay() { } .filter { (_, dest) -> dest == "A" } .sumOf { (machinePart, _) -> machinePart.values.sum() } - .toBigInteger() + .toLong() } else { searchPathes(workflows, listOf("in"), mapOf("x" to 1..4000, "m" to 1..4000, "a" to 1..4000, "s" to 1..4000)) .sumOf { - vc -> vc.values.fold(BigInteger.ONE) { p, r -> p * (r.last - r.first + 1).toBigInteger() } + vc -> vc.values.fold(1L) { p, r -> p * (r.last - r.first + 1).toLong() } } -// listOf("x","m","a","s") -// .map { prop -> -// prop to validConstraints.fold(listOf(1..4000)) { existing, constraint -> -// val range = constraint[prop]!! -// buildList { -// existing -// .sortedBy { it.first } -// .forEach { r -> -// if (r.last < range.first || r.first > range.last || r == range) { -// add(r) -// } else { -// add(r.first until range.first) -// add(max(r.first, range.first)..min(r.last, range.last)) -// add((range.last + 1)..r.last) -// } -// } -// } -// .filter { !it.isEmpty() } -// } -// } -// .map { prop -> -// prop.second -// .map { -// prop.first to it -// } -// } -// .combinations() -// .filter { combination -> -// validConstraints.any { constraint -> -// combination.all { prop -> -// prop.second.first >= constraint[prop.first]!!.first && prop.second.last <= constraint[prop.first]!!.last -// } -// } -// } -// .map { combination -> -// combination.fold(BigInteger.ONE) { product, prop -> product * (prop.second.last - prop.second.first + 1).toBigInteger()} -// } -// .sumOf { it } } } fun Map.constraintBy(rule: Rule): Map { diff --git a/src/test/kotlin/de/linkel/aoc/Day19Test.kt b/src/test/kotlin/de/linkel/aoc/Day19Test.kt index 2804923..cad4214 100644 --- a/src/test/kotlin/de/linkel/aoc/Day19Test.kt +++ b/src/test/kotlin/de/linkel/aoc/Day19Test.kt @@ -1,8 +1,6 @@ package de.linkel.aoc -import java.math.BigInteger - -class Day19Test: AbstractDayTest() { +class Day19Test: AbstractDayTest() { override val exampleA = """ px{a<2006:qkq,m>2090:A,rfg} pv{a>1716:R,A} @@ -22,11 +20,11 @@ hdj{m>838:A,pv} {x=2461,m=1339,a=466,s=291} {x=2127,m=1623,a=2188,s=1013} """.trimIndent() - override val exampleSolutionA = 19114L.toBigInteger() - override val solutionA = 374873L.toBigInteger() + override val exampleSolutionA = 19114L + override val solutionA = 374873L - override val exampleSolutionB = 167409079868000L.toBigInteger() - override val solutionB = BigInteger("122112157518711") + override val exampleSolutionB = 167409079868000L + override val solutionB = 122112157518711L override val implementation = Day19() }