Skip to content

Commit 4a4fe45

Browse files
committed
Day09 - Part 1
1 parent 2f9d9e3 commit 4a4fe45

File tree

4 files changed

+557
-0
lines changed

4 files changed

+557
-0
lines changed

src/main/kotlin/Day09.kt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import kotlin.io.path.readLines
2+
3+
class Day09 : Day {
4+
override fun partOne(filename: String, verbose: Boolean): Long {
5+
val redTiles = filename.asPath().readLines().map {
6+
val (x, y) = it.split(",")
7+
Coordinate(x.toInt(), y.toInt())
8+
}
9+
if (verbose) {
10+
val minX = redTiles.minOf { it.x }
11+
val maxX = redTiles.maxOf { it.x }
12+
val minY = redTiles.minOf { it.y }
13+
val maxY = redTiles.maxOf { it.y }
14+
15+
(minY..maxY).forEach { y ->
16+
(minX..maxX).forEach { x ->
17+
if (Coordinate(x, y) in redTiles) {
18+
print('#')
19+
} else {
20+
print('.')
21+
}
22+
}
23+
println()
24+
}
25+
}
26+
var largestRectangle = 0L
27+
28+
redTiles.forEachIndexed { index, firstTile ->
29+
redTiles.drop(index + 1).forEach { secondTile ->
30+
val ySize = maxOf(firstTile.y, secondTile.y) - minOf(firstTile.y, secondTile.y) + 1
31+
val xSize = maxOf(firstTile.x, secondTile.x) - minOf(firstTile.x, secondTile.x) + 1
32+
val size = ySize.toLong() * xSize.toLong()
33+
if (size > largestRectangle) {
34+
largestRectangle = size
35+
}
36+
}
37+
}
38+
return largestRectangle
39+
}
40+
41+
override fun partTwo(filename: String, verbose: Boolean): Any {
42+
TODO("Not yet implemented")
43+
}
44+
45+
companion object : Day.Main("Day09.txt") {
46+
@JvmStatic
47+
fun main(args: Array<String>) = main()
48+
}
49+
}

0 commit comments

Comments
 (0)