Maze | Try Kotlin

Hi. New here. I’ve only just recently discovered Kotlin and going through the process of absorbing it all now. Really impressed so far, especially with the try.kotlinlang.org and the hands on experience without any software download.

While analysing the Maze example I noticed one possible improvement to the path searching algorithm for your consideration. Function findPath - instead of the line:

if (newCell in visited) continue

you could do:

if (newCell in visited || newCell in queue) continue

It speeds it up a lot. Thanks.

Thanks for spotting that. I believe it would be even better to add newCell to visited right after it was explored, so instead of

queue.offer(newCell)
visited.add(cell)

we could write

queue.offer(newCell)
visited.add(newCell)

Perhaps it was intended to be this way and adding cell instead of newCell was just a typo.

There’re a plenty of ways to improve this example by using the modern API from the standard library.
Thanks again for bringing our attention to it, we’ll take a look.