6 kyu
Simple Fun #140: Circle Slash
248 of 529myjinxin2015
Description:
Task
Suppose there are n
people standing in a circle and they are numbered 1 through n in order.
Person 1 starts off with a sword and kills person 2. He then passes the sword to the next person still standing, in this case person 3. Person 3 then uses the sword to kill person 4, and passes it to person 5. This pattern continues around and around the circle until just one person remains.
What is the number of this person?
Example:
For n = 5
, the result should be 3
.
1 kills 2, passes to 3.
3 kills 4, passes to 5.
5 kills 1, passes to 3.
3 kills 5 and wins.
Input/Output
[input]
integern
The number of people. 1 through n standing in a circle.
1 <= n <= 1e9
[output]
an integer
The index of the last person standing.
Puzzles
Similar Kata:
Stats:
Created | Feb 17, 2017 |
Published | Feb 17, 2017 |
Warriors Trained | 1877 |
Total Skips | 66 |
Total Code Submissions | 4177 |
Total Times Completed | 529 |
JavaScript Completions | 183 |
C# Completions | 72 |
Python Completions | 248 |
Ruby Completions | 37 |
PHP Completions | 47 |
Scala Completions | 7 |
Total Stars | 47 |
% of votes with a positive feedback rating | 89% of 118 |
Total "Very Satisfied" Votes | 95 |
Total "Somewhat Satisfied" Votes | 19 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 6 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |