Skip to content

Commit

Permalink
Added solution for Day 5 (Part 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Dec 5, 2021
1 parent 30267d4 commit f218877
Show file tree
Hide file tree
Showing 3 changed files with 553 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Day05.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import kotlin.math.max
import kotlin.math.min

fun main() {
fun part1(input: List<String>): Int {

val field = Array(1000) { IntArray(1000) }
for (line in input) {
val (x1, y1, x2, y2) = line.split(",", " -> ").map { it.toInt() }
if (x1 == x2) {
val yMin = min(y1, y2)
val yMax = max(y1, y2)
for (y in yMin..yMax)
field[x1][y] += 1
} else if (y1 == y2) {
val xMin = min(x1, x2)
val xMax = max(x1, x2)
for (x in xMin..xMax)
field[x][y1] += 1
}
}

var dangerous = 0
for (x in 0..field.lastIndex) {
for (y in 0..field[0].lastIndex) {
if (field[x][y] > 1) {
dangerous += 1
}
}
}
return dangerous
}

fun part2(input: List<String>): Int {
return 0
}

val input = readInput("Day05")
check(part1(readInput("Day05_test")) == 5)

println(part1(input))
println(part2(input))
}
Loading

0 comments on commit f218877

Please sign in to comment.