Skip to content

Commit

Permalink
day 18 and 19, as well as empty files for days 20-25
Browse files Browse the repository at this point in the history
  • Loading branch information
norganos committed Dec 19, 2023
1 parent 32089ce commit f1c9e97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 50 deletions.
47 changes: 4 additions & 43 deletions src/main/kotlin/de/linkel/aoc/Day19.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<BigInteger>() {
class Day19: AbstractLinesAdventDay<Long>() {
override val day = 19

enum class Op(val char: Char, val lambda: (value: Int, threshold: Int) -> Boolean) {
Expand Down Expand Up @@ -50,7 +49,7 @@ class Day19: AbstractLinesAdventDay<BigInteger>() {
}
}

override fun process(part: QuizPart, lines: Sequence<String>): BigInteger {
override fun process(part: QuizPart, lines: Sequence<String>): Long {
val iterator = lines.iterator()
val rulePattern = Regex("([xmas])([<>])([0-9]+):([a-zAR]+)")
val workflows = iterator
Expand Down Expand Up @@ -84,50 +83,12 @@ class Day19: AbstractLinesAdventDay<BigInteger>() {
}
.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<String,IntRange>.constraintBy(rule: Rule): Map<String,IntRange> {
Expand Down
12 changes: 5 additions & 7 deletions src/test/kotlin/de/linkel/aoc/Day19Test.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package de.linkel.aoc

import java.math.BigInteger

class Day19Test: AbstractDayTest<BigInteger>() {
class Day19Test: AbstractDayTest<Long>() {
override val exampleA = """
px{a<2006:qkq,m>2090:A,rfg}
pv{a>1716:R,A}
Expand All @@ -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()
}

0 comments on commit f1c9e97

Please sign in to comment.