tipsy
12/03/2018, 7:45 PMclaims.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?littlelightcz
12/03/2018, 7:49 PMkarelpeeters
12/03/2018, 7:52 PMinline
function to hide the nested for loops.karelpeeters
12/03/2018, 7:53 PMx = x + 1
is x++
😛 )tipsy
12/03/2018, 8:19 PM