Skip to content

Commit

Permalink
2024 - Day 07 - added a small guard - if acc already exceeds sum we w…
Browse files Browse the repository at this point in the history
…on't ever make them equal.
  • Loading branch information
fmmr committed Dec 7, 2024
1 parent 5e1aec7 commit 8680b52
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/no/rodland/advent_2024/Day07.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Day07(val input: List<String>) : Day<Long, Long, List<Pair<Long, List<Long
.sumOf { it.first }

private fun canBeTrue(sum: Long, acc: Long, values: List<Long>, operators: List<(Long, Long) -> Long>): Boolean {
if (acc > sum) return false
if (values.isEmpty()) return sum == acc
return operators.any { canBeTrue(sum, it.invoke(acc, values.first()), values.drop(1), operators) }
}
Expand Down

0 comments on commit 8680b52

Please sign in to comment.