Skip to content

Commit 742278c

Browse files
committed
Day 17: reduced duplications
1 parent 021008f commit 742278c

File tree

2 files changed

+2
-28
lines changed

2 files changed

+2
-28
lines changed

aoc17/src/main/kotlin/de/havox_design/aoc2022/day17/Chamber.kt

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,11 @@ class Chamber(var width: Long = 7L) {
1616
}
1717

1818
fun addRockToObstaclesIfItCollides(rock: Rock, position: Position, direction: Jet): Boolean {
19-
var realDirection = direction
2019
val rockBlockers = rock
2120
.getBlockedPositions()
2221
.map { pos -> pos + position }
2322
.toList()
24-
25-
// We cannot be blown out of the tunnel
26-
if (
27-
(
28-
direction == Jet.LEFT
29-
&& (
30-
rockBlockers
31-
.any { pos -> pos.x == 0L }
32-
|| rockBlockers
33-
.map { pos -> pos + Position.getPositionForJet(Jet.LEFT) }
34-
.any { pos -> obstacles.contains(pos) }
35-
)
36-
)
37-
|| (
38-
direction == Jet.RIGHT
39-
&& (
40-
rockBlockers
41-
.any { pos -> pos.x == width - 1 }
42-
|| rockBlockers
43-
.map { pos -> pos + Position.getPositionForJet(Jet.RIGHT) }
44-
.any { pos -> obstacles.contains(pos) }
45-
)
46-
)
47-
) {
48-
realDirection = Jet.UNKNOWN
49-
}
23+
val realDirection = getRealDirection(rock, position, direction)
5024

5125
// Do we collide with floor or another stone?
5226
if (

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
// project meta data
66
group 'de.havox_design.aoc2022'
7-
version '0.17.7'
7+
version '0.17.8'
88

99
// Switch to gradle "all" distribution.
1010
wrapper {

0 commit comments

Comments
 (0)