The world of work - 3.part(correct version)

Your second mission:

On your first raid, you got into a duel with two other people. All of you have only one gun. The rules of this duel are rather peculiar: the duelists do not all shoot simultaneously, but take turns. A can fire at B, B can fire at C, and C can fire at A; the cycle repeats until there is a single survivor. If you hit your target, you'll fire the next person on your next turn.

You are A. What are your chances of surviving? If none of you shoot, you will explode. Give your answer in % and round up!

Report room - Here you will see the other parts of the series too.


The answer is 50.

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

You can see these things:

  • If you shoot, then B will shoot, C won't
  • If you don't shoot, B won't shoot, but C will.

So if you shoot your chances: p 1 ( A ) = 0.7 p ( C A ) + 0.9 ( 1 0.7 ) p ( A B ) + ( 1 0.7 ) ( 1 0.9 ) p 1 ( A ) p_1(A)=0.7p(CA)+0.9(1-0.7)p(AB)+(1-0.7)(1-0.9)p_1(A) Where p(CA) is the probability to win a duel with C, if C is the first shooter, and p(AB) where you are the first shooter. p ( C A ) = 0.7 ( 1 0.5 ) + ( 1 0.7 ) ( 1 0.5 ) p ( C A ) p ( A B ) = 0.7 + ( 1 0.7 ) ( 1 0.9 ) p ( A B ) \begin{aligned}p(CA)&=0.7(1-0.5)+(1-0.7)(1-0.5)p(CA)\\ p(AB)&=0.7+(1-0.7)(1-0.9)p(AB)\end{aligned} So: p 1 ( A ) = 0.7 0.7 0.5 1 0.3 0.5 + 0.9 0.3 0.7 1 0.3 0.1 1 0.3 0.1 = 0.7 0.35 1 0.15 + 0.27 0.7 1 0.03 1 0.03 = 0.245 0.85 + 0.189 0.97 0.97 50 % \begin{aligned}p_1(A)&=\cfrac{0.7\cfrac{0.7\cdot0.5}{1-0.3\cdot0.5}+0.9\cdot0.3\cfrac{0.7}{1-0.3\cdot0.1}}{1-0.3\cdot0.1}\\ &=\cfrac{0.7\cfrac{0.35}{1-0.15}+0.27\cfrac{0.7}{1-0.03}}{1-0.03}\\ &=\cfrac{\cfrac{0.245}{0.85}+\cfrac{0.189}{0.97}}{0.97}\\ &\approx50\%\end{aligned} And if you don't shoot, then B won't shoot too and C will shoot you, until he don't kill you, so your chances 0% in this case. 50 % > 0 % 50 % 50\%>0\%\Rightarrow\boxed{50\%}

Here is my C++ code:

Description: You can set these numbers: number_of_duels , max_precision , precision_A , precision_B , precision_C . This code doesn't use formulas because this code was written to show you the formulas I used are correct. With these settings the code will run for 10 seconds. With 1 0 8 10^8 duels approxinetly for 15-20 minutes.

  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
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
typedef long long int big;
big number_of_duels=10000000;

big sum_A;
big sum_B;
big sum_C;
/*Maximum precision is 100*/
int max_precision=100;

int precision_A=70;
int precision_B=90;
int precision_C=50;

int dont_shoot_A=0;
int dont_shoot_B=0;
int dont_shoot_C=0;

const int A=0;
const int B=1;
const int C=2;

void zeros(int x);
int shoot(int x);

int A_B_C();
int B_C_A();
int C_A_B();

int C_A();
int A_C();
int A_B();
int B_A();
int B_C();
int C_B();

int main()
{
    srand(time(0));
    int temp;
    for(dont_shoot_A=0;dont_shoot_A<2;dont_shoot_A++){
        for(dont_shoot_B=0;dont_shoot_B<2;dont_shoot_B++){
            for(dont_shoot_C=0;dont_shoot_C<2;dont_shoot_C++){
                if(dont_shoot_A==1&&dont_shoot_B==1&&dont_shoot_C==1) break;
                sum_A=0;
                sum_B=0;
                sum_C=0;
                for(int current_duel=0;current_duel<number_of_duels;current_duel++){
                    temp=A_B_C();
                    if(temp==A) sum_A++;
                    else if(temp==B)    sum_B++;
                    else if(temp==C)    sum_C++;
                    else cout << "error!!!!!";
                }
                cout << "\n\nA:" << dont_shoot_A << "\tB:" << dont_shoot_B << "\tC:" << dont_shoot_C;
                cout << "\n0.";
                zeros(A);
                cout << sum_A;
                cout << "\t0.";
                zeros(B);
                cout << sum_B;
                cout << "\t0.";
                zeros(C);
                cout << sum_C;
            }
        }
    }
    return 0;
}
void zeros(int x){
    int zeros_number_of_duels=log10(number_of_duels);
    int zeros_sum;
    if(x==A){
        if(sum_A)    zeros_sum=log10(sum_A);
        else return;
    }else if(x==B){
        if(sum_B)    zeros_sum=log10(sum_B);
        else return;
    }else if(x==C){
        if(sum_C)    zeros_sum=log10(sum_C);
        else return;
    }
    for(int y=1;y<zeros_number_of_duels-zeros_sum;y++)  cout << 0;
}
int shoot(int x){
    if(x==A)  return ((rand()%max_precision+1)>precision_A);
    if(x==B)  return ((rand()%max_precision+1)>precision_B);
    if(x==C)  return ((rand()%max_precision+1)>precision_C);
}
int A_B_C(){
    int missed=shoot(A);
    if(!dont_shoot_A)    return (missed)? B_C_A():C_A();
    else return B_C_A();
}
int B_C_A(){
    int missed=shoot(B);
    if(!dont_shoot_B)    return (missed)? C_A_B():A_B();
    else return C_A_B();
}
int C_A_B(){
    int missed=shoot(C);
    if(!dont_shoot_C)   return (missed)? A_B_C():B_C();
    else return A_B_C();
}
int C_A(){
    int missed=shoot(C);
    return (missed)? A_C():C;
}
int A_C(){
    int missed=shoot(A);
    return (missed)? C_A():A;
}
int A_B(){
    int missed=shoot(A);
    return (missed)? B_A():A;
}
int B_A(){
    int missed=shoot(B);
    return (missed)? A_B():B;
}
int B_C(){
    int missed=shoot(B);
    return (missed)? C_B():B;
}
int C_B(){
    int missed=shoot(C);
    return (missed)? B_C():C;
}

Output:

Without the first and second lines. max_precision=1000,000,000

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
A:0 B:0 C:0
0.490251313 0.090364688 0.419383999

A:0 B:0 C:1
0.497812583 0.077167163 0.425020254

A:0 B:1 C:0
0.338967042 0.166930172 0.494102786

A:0 B:1 C:1
0.411526617 0.0 0.588473383

A:1 B:0 C:0
0.684252147 0.312983441 0.002764412

A:1 B:0 C:1
0.722186746 0.277813254 0.0

A:1 B:1 C:0
0.0 0.947433430 0.052566570

I can declarate lots of variables in a line and I can use arrays, but this is a copy-paste code. You can optimise the code if you use a function with two input instead of C_A(), A_C(), A_B(), B_A(), B_C(), C_B() and a function with three input, and if you use arrays etc.

A Former Brilliant Member - 11 months, 1 week ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...