After having his demon henchmen thwarted by the cunning mathematician village chiefs of Earth,the devil himself comes down to Earth to get rid of the problem once and for all.
Confidently he snarls
" All you people of Earth stand in a large CIRCLE and number yourself starting from to . I will devour every person and keep going around and around the circle eating up every person and keep doing this till there is only person left. That last person I will spare and he is free to escape. "
You are the last living descendant of the mathematician village chiefs and need to ensure that you survive so that mathematics will not perish from Earth.
Which number will you choose to be the last person standing and escape the clutches of Satan ?
Details and assumptions
Example
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Python 2 solution (takes a few seconds but too long):
I didn't use recursion because max. recursion depth is exceeded.