id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

frew@mclean.com > josephusQueue
prev  |  next  |  chance

In the Josephus problem from antiquity, numPeople people are in dire straits and agree to the following strategy to reduce the population. They arrange themselves in a circle (at positions numbered from 0 to numPeople-1) and proceed around the circle, eliminating every elim person until only one person is left. Legend has it that Josephus figured out where to sit to avoid being eliminated. Return where Josephus should sit.


josephusQueue(2, 7) → 6
josephusQueue(2, 4) → 0
josephusQueue(3, 41) → 30

...Save, Compile, Run (ctrl-enter)

public int josephusQueue(int elim, int numPeople) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 300 Post-solution available

Copyright Nick Parlante 2017 - privacy