in the challenge today i iterated through the clai...
# advent-of-code
t
in the challenge today i iterated through the claims and their cells twice:
Copy code
claims.forEach { claim ->
    for (row in claim.x until claim.x + claim.width) {
        for (col in claim.y until claim.y + claim.height) {
            countArray[row][col] = countArray[row][col] + 1
        }
    }
}

println("part 1: ${countArray.flatMap { it.asIterable() }.count { it > 1 }}")

claims.forEach { claim ->
    for (row in claim.x until claim.x + claim.width) {
        for (col in claim.y until claim.y + claim.height) {
            if (countArray[row][col] != 1) {
                return@forEach
            }
        }
    }
    println("part 2: ${claim.id}")
}
i don't really want to change the approach, but is there a nicer way of iterating?
l
Nice one - very similar to mine 😁 . But I don't think there is a better way of iterating in this case though.
👍 1
k
I wrote an
inline
function to hide the nested for loops.
(also
x = x + 1
is
x++
😛 )
t
i prefer the explicit form when dealing with arrays