Skip to content

Commit

Permalink
[2024/7] Bridge Repair (Part 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfolta committed Dec 7, 2024
1 parent 1d3c049 commit a52ef94
Show file tree
Hide file tree
Showing 5 changed files with 890 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
| 2021 | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | | β˜… | β˜… | | | | | | | | | | | | 26 |
| 2022 | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | | | | | | | | β˜† | | | | β˜† | 28 |
| 2023 | β˜… | β˜… | β˜… | β˜… | β˜† | β˜… | β˜† | | | | | | | | | | | | | | | | | | | 12 |
| 2024 | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | | | | | | | | | | | | | | | | | | | | 12 |
| 2024 | β˜… | β˜… | β˜… | β˜… | β˜… | β˜… | β˜† | | | | | | | | | | | | | | | | | | | 13 |

## πŸ›· How to run

Expand Down Expand Up @@ -170,6 +170,7 @@ e.g. `HandyHaversacks`)*
| | 4 | [Ceres Search](https://adventofcode.com/2024/day/4) | [[Code](src/main/kotlin/adventofcode/year2024/Day04CeresSearch.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day04CeresSearchSpec.kt)] | `2483` | `1925` |
| | 5 | [Print Queue](https://adventofcode.com/2024/day/5) | [[Code](src/main/kotlin/adventofcode/year2024/Day05PrintQueue.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day05PrintQueueSpec.kt)] | `6498` | `5017` |
| | 6 | [Guard Gallivant](https://adventofcode.com/2024/day/6) | [[Code](src/main/kotlin/adventofcode/year2024/Day06GuardGallivant.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day06GuardGallivantSpec.kt)] | `5212` | `1767` |
| | 7 | [Bridge Repair](https://adventofcode.com/2024/day/7) | [[Code](src/main/kotlin/adventofcode/year2024/Day07BridgeRepair.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day07BridgeRepairSpec.kt)] | `8401132154762` | |

## πŸ•―οΈ Useful commands

Expand Down
24 changes: 24 additions & 0 deletions src/main/kotlin/adventofcode/year2024/Day07BridgeRepair.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package adventofcode.year2024

import adventofcode.Puzzle
import adventofcode.PuzzleInput

class Day07BridgeRepair(customInput: PuzzleInput? = null) : Puzzle(customInput) {
override fun partOne() =
input
.lines()
.mapNotNull { equation ->
val result = equation.split(": ").first().toLong()
val numbers = equation.split(": ").last().split(" ").map(String::toLong)

val results =
numbers
.drop(1)
.fold(setOf(numbers.first())) { candidates, number ->
candidates.flatMap { candidate -> setOf(candidate + number, candidate * number) }.toSet()
}

if (result in results) result else null
}
.sum()
}
Loading

0 comments on commit a52ef94

Please sign in to comment.