CTK Exchange
Front Page
Movie shortcuts
Personal info
Awards
Reciprocal links
Terms of use
Privacy Policy

Interactive Activities

Cut The Knot!
MSET99 Talk
Games & Puzzles
Arithmetic/Algebra
Geometry
Probability
Eye Opener
Analog Gadgets
Inventor's Paradox
Did you know?...
Proofs
Math as Language
Things Impossible
My Logo
Math Poll
Other Math sit's
Guest book
News sit's

Recommend this site

Manifesto: what CTK is about Search CTK Buying a book is a commitment to learning Table of content Products to download and subscription Things you can find on CTK Chronology of updates Email to Cut The Knot Recommend this page

CTK Exchange

Subject: "Josephus Flavius - a generalized solution"     Previous Topic | Next Topic
Printer-friendly copy     Email this topic to a friend    
Conferences The CTK Exchange Thoughts and Suggestions Topic #39
Reading Topic #39
David Turner
guest
May-14-08, 08:17 AM (EST)
 
"Josephus Flavius - a generalized solution"
 
   Hiya... I've derived a general solution for the Josephus Flavius problem, but it's a bit awkward to express in conventional mathematical notation. I'd be interested to see if anyone can convert this to a closed form.

In Python:


def flavius(n, p):
if n == 1: return 0
if n < p: return (flavius(n - 1, p) + p) % n
q, r = n/p, n%p
i = flavius(n - q, p) - r
if i < 0: return i + n
return i + i / (p - 1)

Or as a piecewise function:


f(n, p) = { 0, n = 1
( f(n-1, p) + p (mod n), n < p
( f(n-q, p) - r + n, f(n-q, p) < r
( f(n-q, p) x (p/) otherwise

where q is the quotient (n-r)/p and r is the remainder n (mod p).

Note that this function returns the zero-based index of the survivor.


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top

Conferences | Forums | Topics | Previous Topic | Next Topic

You may be curious to have a look at the old CTK Exchange archive.
Please do not post there.

Copyright © 1996-2018 Alexander Bogomolny

Search:
Keywords:

Google
Web CTK