bjonnh
12/11/2020, 4:48 AMDavid Whittaker
12/11/2020, 6:00 AMDavid Whittaker
12/11/2020, 6:00 AMephemient
12/11/2020, 6:52 AMephemient
12/11/2020, 6:53 AMandyb
12/11/2020, 10:16 AMNir
12/11/2020, 3:11 PMNir
12/11/2020, 3:12 PMNir
12/11/2020, 3:37 PMmap
is Sequence<Any> rather than Sequence<Int>. Can anyone point out the easiest way to solve this? Is my return qualified correctly?
fun SeatMap.visibleNeighbors(p: Point) = directionPoints().map {
var point = p
while (true) {
point += it
if (point !in this || getSeat(point) == Seat.EMPTY) {
return@map 0
}
if (getSeat(point) == Seat.OCCUPIED) {
return@map 1
}
}
}.sum()
Nir
12/11/2020, 3:39 PMNir
12/11/2020, 4:57 PMfun SeatMap.visibleNeighbors(p: Point) = directionPoints().map { dirPoint ->
val first = generateSequence(p + dirPoint) { it + dirPoint }
.filter { getSeat(it) != Seat.EMPTY }
.first()
when (getSeat(first)) {
null, Seat.EMPTY -> 0
Seat.OCCUPIED -> 1
else -> throw Exception("")
}
}.sum()
ephemient
12/11/2020, 5:57 PMtodd.ginsberg
12/11/2020, 6:20 PMtodd.ginsberg
12/11/2020, 6:21 PM