Counting game

There are 2019 people playing a game. They stand in a line, and they are labeled No.1 to No.2019 from the front to the back of the line. In each round, the first person of the line says 1, then the second person says 2, ... when the last person of the line says his number, it comes back to the first person. It goes on and on, until one of them says 2019, then that person is eliminated. For example, in the first, second, third, fourth round, No. 2019, No. 1, No. 3, No. 5 are eliminated respectively.

There is only one person left when they have played for 2018 rounds. What is the number of the person?


The answer is 6.

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.

1 solution

Chase Marangu
Mar 22, 2019

Ima beast this took less than a second to spit out the answer also it took a bit longer than that to write the code Pure Javascript put it in a HTML document and run and the answer before ur eyes I prefer document.write(stuff) to console.log(stuff) because the consoles always crowded up with nonsense

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* make an array of 2019 people with their names conveniently equal to their number */
var people = [];
for (var i=1; i<=2019; i++) {
    people.push(i);
}

/* count is the number which goes up when theyre counting in a circle when it hits 2019 that person eliminated */
/* index is the number that loops around when the last person in the line says his number */
var count = 1;
var index = 0;

/* play the game until theres only 1 person in the array */
while (people.length > 1) {
    /* check whether the count has reached 2019 to eliminate someone */
    if (count === 2019) {
        /* alternative to people.splice(index, 1); */
        // people = people.slice(0, index).concat(people.slice(index, people.length));
        /* eliminate the person from the array */
        people.splice(index, 1);
        /* reset the numbers */
        count = 1;
        index = 0;
    }
    /* increment the count and index */
    count++;
    index++;
    /* loops back if you reach the person at the end of the line */
    index%=people.length;
}
/* write the answer so you can conveniently see it on the computer screen */
document.write(people);

1 pending report

Vote up reports you agree with

×

Problem Loading...

Note Loading...

Set Loading...