-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoinflip.sh
58 lines (45 loc) · 1.05 KB
/
coinflip.sh
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
#Extend the Flip Coin problem till either Heads or Tails wins 11 times.
headcount=0
tailcount=0
for (( i=0; i<10; i++))
do
flip=$(($RANDOM%2))
echo $flip
if [ $flip -eq 0 ]
then
tailcount=$(($tailcount+1))
else
headcount=$(($headcount+1))
fi
done
echo "Tail Count " $tailcount
echo "Head Count " $tailcount
if [ $headcount -gt $tailcount ]
then
echo "Head wins"
elif [ $tailcount -gt $headcount ]
then
echo "Tail wins"
else
echo "Game Tied"
for (( 1=0; i<=3; i++))
do
flip=$(($RANDOM%2))
echo $flip
if [ $flip -eq 0 ]
then
tailcount=$(($tailcount+1))
else
headcounr=$(($headcount+1))
fi
done
echo "Tailcount = " $tailcount
echo "Headcount = " $headcount
if [ $headcount -gt $tailcount ]
then
echo "Head wins"
elif [ $tailcount -gt $headcount ]
then
echo "Tail wins"
fi
fi