Skip to content

Commit

Permalink
[2024/5] Print Queue (Part 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfolta committed Dec 5, 2024
1 parent 731d1ea commit 7d60244
Show file tree
Hide file tree
Showing 5 changed files with 1,428 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 | β˜… | β˜… | β˜… | β˜… | | | | | | | | | | | | | | | | | | | | | | 8 |
| 2024 | β˜… | β˜… | β˜… | β˜… | β˜† | | | | | | | | | | | | | | | | | | | | | 9 |

## πŸ›· How to run

Expand Down Expand Up @@ -168,6 +168,7 @@ e.g. `HandyHaversacks`)*
| | 2 | [Red-Nosed Reports](https://adventofcode.com/2024/day/2) | [[Code](src/main/kotlin/adventofcode/year2024/Day02RedNosedReports.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day02RedNosedReportsSpec.kt)] | `572` | `612` |
| | 3 | [Mull It Over](https://adventofcode.com/2024/day/3) | [[Code](src/main/kotlin/adventofcode/year2024/Day03MullItOver.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day03MullItOverSpec.kt)] | `174960292` | `56275602` |
| | 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` | |

## πŸ•―οΈ Useful commands

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

import adventofcode.Puzzle
import adventofcode.PuzzleInput

class Day05PrintQueue(customInput: PuzzleInput? = null) : Puzzle(customInput) {
private val rules by lazy {
input.split("\n\n").first().lines().map { line -> line.split("|").map(String::toInt) }
}

private val updates by lazy {
input.split("\n\n").last().lines().map { line -> line.split(",").map(String::toInt) }
}

override fun partOne() =
updates
.mapNotNull { update ->
val filteredRules = rules.filter { rule -> update.containsAll(rule) }

if (filteredRules.containsAll(update.windowed(2))) {
update[update.size / 2]
} else {
null
}
}
.sum()
}
Loading

0 comments on commit 7d60244

Please sign in to comment.