Maze-walking algorithm

Last week, a colleague pointed out to my team an online developer recruitment challenge. As I find it fun and there was no need to disclose one’s email, I decided to try, just to check if I could to it. The problem is quite simple but not easy: consider a rectangular maze of finite size. One has to find a specific cell on the board - the exit, starting from the origin. One has 2 move options: one cell at a time in one of the 4 cardinal points or jumping to any previously visited cell. Of

algorithm kotlin

Feedback on the Josephus problem

My last week article was about the solving the Josephus problem in Kotlin. For ease of comparison, here’s the version I wrote originally: class Soldier(val position: Int) { var state = State.Living lateinit var next: Soldier fun suicide() { state = State.Dead } fun isDead() = state == State.Dead } enum class State { Living, Dead } class Circle(private val size: Int, private val step: Int) { private val first = Soldier(0) init { var p

algorithm kotlin

Solving the Josephus problem in Kotlin

I recently stumbled upon a post telling about the Josephus problem and trying to solve it in different scripting languages. For the sake of brevity, here’s the problem (taken from the referenced post): Flavius Josephus was a roman historian of Jewish origin. During the Jewish-Roman wars of the first century AD, he was in a cave with fellow soldiers, 40 men in all, surrounded by enemy Roman troops. They decided to commit suicide by standing in a ring and counting off each third man. Each