Skip to content

Commit 16332aa

Browse files
committed
A small graphical representation for part one
1 parent 3ea7efd commit 16332aa

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/main/kotlin/Day14.kt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,38 @@ fun main() {
3333
counts
3434
}
3535

36+
fun List<Robot>.toGrid(
37+
width: Int,
38+
height: Int
39+
): List<List<Int>> {
40+
val grid = MutableList(height) { MutableList(width) { 0 } }
41+
forEach {
42+
grid[it.py][it.px]++
43+
}
44+
return grid
45+
}
46+
47+
fun List<List<Int>>.print() {
48+
forEach { row ->
49+
row.forEach {
50+
when (it) {
51+
0 -> print('.')
52+
else -> print(it.digitToChar())
53+
}
54+
}
55+
println()
56+
}
57+
}
58+
3659
fun part1Small(input: List<String>): Int {
3760
val width = 11
3861
val height = 7
39-
val (q1, q2, q3, q4) = input.parseRobots()
40-
.move(width, height, 100)
41-
.countQuadrants(width, height)
62+
val robots = input.parseRobots()
63+
robots.toGrid(width, height).print()
64+
println("---------------------")
65+
val robotsMoved = robots.move(width, height, 100)
66+
robotsMoved.toGrid(width, height).print()
67+
val (q1, q2, q3, q4) = robotsMoved.countQuadrants(width, height)
4268
return q1 * q2 * q3 * q4
4369
}
4470

0 commit comments

Comments
 (0)