Simplified Josephus

Published by 11level360 in

Given n people, find the survivor. Starting from the first person, they kill the person to their left and the next surviving person kills the person to their left. This keeps happening until 1 person survives. Return that person's number.

Examples

josephus(1) ➞ 1

josephus(8) ➞ 1

josephus(41) ➞ 19

Notes

Check the resources if you are confused about the instructions.

Watch a quick demo on how Edabit works.