Flavius Josephus in Haskell

My first Haskell solution for a programming praxis challenge, and this time I almost nailed it.

Almost, because even with a clear specification of the expected result I still managed to lose focus for a moment, and went for a “fancy” solution that doesn’t quite qualify as a solution. What I want to say is that instead of returning a list ordered with the people who have died, I have only returned the last person killed.

The “fancy” part of it is, that it returns the last person killed by solving the problem for each varying number of people from 1..n.

Considering it’s 2AM, I’m going to leave it as it is and pretend that everything went better than expected :)

For the correct Haskell solution check the first comment on the challenge page.

Also found a couple of variations of the Haskell solution on reddit.

P.S.I would have had it right if I would have sticked with my first idea consisting of a cycled list and an incrementing step.

Filed under Challenge, Code