Shooting Zone

100 people are sitting on a big round table such that (1,2),(2,3),...,(100,1) are next to each other. 1 has a gun with him. He shoots 2 and gives the gun to 3. 3 shoots 4 and passes gun to 5 (if 100 gets gun he will shoot the next living person). This continues till one person remains alive. Which person is alive?

  • eg. Answer 40 if 40 is alive.

Hint : Start with small number of person sitting on the table and solve that. You will get a pattern. Then solve this.

For part 2 Shooting Zone 2


The answer is 73.

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.

2 solutions

Jack D'Aurizio
Apr 15, 2014

Let "the champion" be the living person with the smallest index, and let a "turn" end when the gun crosses the 100-1 line. After every turn, the champion changes if and only if the number of survivors is odd; in that case its index increases by a power of two given by the turn number. This gives that if n n people around a table play this kind of determistic russian roulette, the index of the last survivor is given by 2 ( n 2 log 2 n ) + 1 , 2\cdot\left(n-2^{\left\lfloor\log_2 n \right\rfloor}\right)+1, that is a cyclic shift of the binary representation of n n , where the leading 1 1 becomes the least significant bit.

Hà Vĩnh Đạt
Apr 5, 2014

This can be solved by computer science: using C/C++ complier: //Linked List struct Node { int _Val; Node* _pNext; };

void deleteNode(Node* & head, Node* _del) { Node* cur = _head; if (cur == _del) { Node* cur 2 = head; while (cur 2-> pNext != _head) cur 2 = cur 2-> pNext; //cur 2 in the tail Node* temp = cur-> pNext; delete cur; head = temp; cur 2-> pNext = _head; } else { while (cur-> pNext != head) { if (cur-> pNext == del) { Node* temp = cur-> pNext-> pNext; delete cur-> pNext; cur-> pNext = temp; } cur = cur-> pNext; } } }

int countEle(Node* head) { int c = 1; Node* cur = _head; if (cur-> pNext == head) return c; while (cur-> pNext != head) { c++; cur = cur-> pNext; } return c; }

void main() { Node* head = NULL; //Create circle linked list for (int i = 1; i <= 100; i++) { if (head == NULL) { head = new Node; head-> Val = i; head-> pNext = head; } else { Node* cur = head; while (cur-> pNext != head) cur = cur-> pNext; cur-> pNext = new Node; cur-> pNext-> Val = i; cur-> pNext-> pNext = head; } } //============================ Node* cur = head; while (countEle(head) != 1) { deleteNode(head, cur-> pNext); cur = cur-> pNext; } cout << cur-> Val << endl; }

I appreciate that you solved it using programming.

Can you solve the same problem if there were 8589934598 8589934598 people instead of just 100 100 . ( The pattern used for solving this type of question will definitely solve it easily )

Shahbaz Patel - 7 years, 2 months ago

Log in to reply

why dont you tell the pattern bcoz many of us can't recognize it as we r not as intelligent as u r

Prajwal Kavad - 7 years, 1 month ago

Log in to reply

sarcastic flattery i would say. :P

I wrote a solution in part 2 of the question. You can go solve that. Best of luck! :)

Shahbaz Patel - 7 years, 1 month ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...