Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 43s1 days 16 hours 1 minutes 43 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 43s1 days 16 hours 1 minutes 43 seconds.

Sign in to watch this lesson
Advanced - Combinatorics, Games and Puzzles · 4:00
People stand in a circle and every k-th one is removed until one is left. Instead of simulating, we relabel the circle after the first removal and get the recurrence J(n) = (J(n-1) + k) mod n, which runs as a single loop in linear time and constant memory. For k = 2 the survivor has a closed form, two times the distance past the largest power of two, plus one.