Day 9. Removed all smart code.
This commit is contained in:
parent
9a2a22805b
commit
d2044f2d6a
@ -3,7 +3,6 @@ package aoc2025
|
|||||||
import println
|
import println
|
||||||
import readInput
|
import readInput
|
||||||
import splitInts
|
import splitInts
|
||||||
import java.util.*
|
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -13,7 +12,6 @@ https://adventofcode.com/2025/day/9
|
|||||||
fun main() {
|
fun main() {
|
||||||
|
|
||||||
val inlineTestInput = """
|
val inlineTestInput = """
|
||||||
7,3
|
|
||||||
7,1
|
7,1
|
||||||
11,1
|
11,1
|
||||||
11,7
|
11,7
|
||||||
@ -21,6 +19,7 @@ fun main() {
|
|||||||
9,5
|
9,5
|
||||||
2,5
|
2,5
|
||||||
2,3
|
2,3
|
||||||
|
7,3
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fun part1(input: List<String>): Long {
|
fun part1(input: List<String>): Long {
|
||||||
@ -34,18 +33,6 @@ fun main() {
|
|||||||
return maxArea
|
return maxArea
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findRanges(set: TreeMap<Int, ArrayList<IntRange>>, x1: Int, y1: Int, x2: Int, y2: Int): Boolean {
|
|
||||||
var it = set.ceilingEntry(y1)
|
|
||||||
while (it != null && it.key <= y2) {
|
|
||||||
val xRanges = it.value.filter { it.first() >= x1 && it.last() <= x2 }
|
|
||||||
if (it.key != y1 && it.key != y2 && xRanges.size > 0) return false
|
|
||||||
if ((it.key == y1 || it.key == y2) && xRanges.size > 1) return false
|
|
||||||
// Java TreeMap is crap -- I would like to iterate from first entry to last
|
|
||||||
it = set.ceilingEntry(it.key + 1)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun intersects(coords: List<List<Int>>, x1: Int, y1: Int, x2: Int, y2: Int): Boolean {
|
fun intersects(coords: List<List<Int>>, x1: Int, y1: Int, x2: Int, y2: Int): Boolean {
|
||||||
for (z1 in 0 until coords.size) {
|
for (z1 in 0 until coords.size) {
|
||||||
val z2 = if (z1 != coords.size - 1) z1 + 1 else 0
|
val z2 = if (z1 != coords.size - 1) z1 + 1 else 0
|
||||||
@ -72,44 +59,16 @@ fun main() {
|
|||||||
|
|
||||||
fun part2(input: List<String>): Long {
|
fun part2(input: List<String>): Long {
|
||||||
val coords = input.map { it.splitInts(",") }
|
val coords = input.map { it.splitInts(",") }
|
||||||
val xSpans = TreeMap<Int, ArrayList<IntRange>>()
|
|
||||||
val ySpans = TreeMap<Int, ArrayList<IntRange>>()
|
|
||||||
for (i1 in 0 until coords.size) {
|
|
||||||
val i2 = if (i1 != coords.size - 1) i1 + 1 else 0
|
|
||||||
if (i1 and 1 == 1) {
|
|
||||||
xSpans.getOrPut(coords[i1][1]) { ArrayList<IntRange>() }.add(
|
|
||||||
IntRange(
|
|
||||||
coords[i1][0].coerceAtMost(coords[i2][0]),
|
|
||||||
coords[i1][0].coerceAtLeast(coords[i2][0])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
ySpans.getOrPut(coords[i1][0]) { ArrayList<IntRange>() }.add(
|
|
||||||
IntRange(
|
|
||||||
coords[i1][1].coerceAtMost(coords[i2][1]),
|
|
||||||
coords[i1][1].coerceAtLeast(coords[i2][1])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//xSpans.values.forEach { it.sortBy { it.first } }
|
|
||||||
//ySpans.values.forEach { it.sortBy { it.first } }
|
|
||||||
|
|
||||||
var maxArea = 0L
|
var maxArea = 0L
|
||||||
for (i1 in 0 until coords.size step 1) {
|
for (i1 in 0 until coords.size step 2) {
|
||||||
for (i2 in i1 + 1 until coords.size step 1) {
|
for (i2 in i1 + 2 until coords.size step 2) {
|
||||||
val x1 = coords[i1][0].coerceAtMost(coords[i2][0])
|
val x1 = coords[i1][0].coerceAtMost(coords[i2][0])
|
||||||
val x2 = coords[i1][0].coerceAtLeast(coords[i2][0])
|
val x2 = coords[i1][0].coerceAtLeast(coords[i2][0])
|
||||||
val y1 = coords[i1][1].coerceAtMost(coords[i2][1])
|
val y1 = coords[i1][1].coerceAtMost(coords[i2][1])
|
||||||
val y2 = coords[i1][1].coerceAtLeast(coords[i2][1])
|
val y2 = coords[i1][1].coerceAtLeast(coords[i2][1])
|
||||||
if (x1 == x2 || y1 == y2) continue
|
|
||||||
|
|
||||||
val area = ((x2 - x1 + 1).toLong() * (y2 - y1 + 1).toLong())
|
val area = ((x2 - x1 + 1).toLong() * (y2 - y1 + 1).toLong())
|
||||||
if (area > maxArea) {
|
if (area > maxArea) {
|
||||||
// if (!findRanges(xSpans, x1, y1, x2, y2) ||
|
|
||||||
// !findRanges(ySpans, y1, x1, y2, x2)
|
|
||||||
// ) continue
|
|
||||||
if (!intersects(coords, x1, y1, x2, y2))
|
if (!intersects(coords, x1, y1, x2, y2))
|
||||||
maxArea = area
|
maxArea = area
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user