-
Notifications
You must be signed in to change notification settings - Fork 0
/
flip.sh
130 lines (114 loc) · 2.47 KB
/
flip.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
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
#!/bin/bash -x
let -A flipstore
read -p "enter the no. of times to flip coin" n
head=0
tail=0
hh=0
ht=0
th=0
tt=0
coin1=0
coin2=0
ttt=0
htt=0
tht=0
tth=0
hht=0
hth=0
thh=0
hhh=0
function singlet()
{
for (( i=0 ; i<$1 ; i++ ))
{
val=$((RANDOM%2))
if [ $val -eq 0 ]
then
(( head++ ))
else
(( tail++ ))
fi
}
}
singlet $((n))
echo "the value of head is" $head
echo "the value of tails is" $tail
echo "the percentages of heads and tails are as: "
headper=$(( ($head*100) / n ))
tailper=$(( ($tail*100) / n ))
function doublet()
{
for (( i=0 ; i<$1 ; i++ ))
{
coin1=$((RANDOM%2))
coin2=$((RANDOM%2))
if [ $coin1 -eq 0 ] && [ $coin2 -eq 0 ]
then ((hh++))
elif [ $coin1 -eq 0 ] && [ $coin2 -eq 1 ]
then ((ht++))
elif [ $coin1 -eq 1 ] && [ $coin2 -eq 0 ]
then ((th++))
else
((tt++))
fi
}
}
doublet $((n))
echo "hh" $hh
echo "ht" $ht
echo "th" $th
echo "tt" $tt
hhper=$(( ($hh*100) / n ))
htper=$(( ($ht*100) / n ))
thper=$(( ($th*100) / n ))
ttper=$(( ($tt*100) /n ))
function triplet()
{
for (( i=0 ; i<$1 ; i++ ))
{
coin1=$((RANDOM%2))
coin2=$((RANDOM%2))
coin3=$((RANDOM%2))
if [ $coin1 -eq 0 ] && [ $coin2 -eq 0 ] && [ $coin3 -eq 1 ]
then ((ttt++))
elif [ $coin1 -eq 0 ] && [ $coin2 -eq 0 ] && [ $coin3 -eq 0 ]
then ((htt++))
elif [ $coin1 -eq 0 ] && [ $coin2 -eq 1 ] && [ $coin3 -eq 1 ]
then ((tht++))
elif [ $coin1 -eq 0 ] && [ $coin2 -eq 1 ] && [ $coin3 -eq 0 ]
then ((tth++))
elif [ $coin1 -eq 1 ] && [ $coin2 -eq 0 ] && [ $coin3 -eq 1 ]
then ((hht++))
elif [ $coin1 -eq 1 ] && [ $coin2 -eq 0 ] && [ $coin3 -eq 0 ]
then ((hth++))
elif [ $coin1 -eq 1 ] && [ $coin2 -eq 1 ] && [ $coin3 -eq 1 ]
then ((thh++))
else
((hhh++))
fi
}
}
triplet $((n))
tttper=$(( ($ttt * 100) / n ))
httper=$(( ($htt * 100) / n ))
thtper=$(( ($tht * 100) / n ))
tthper=$(( ($tth * 100) / n ))
hhtper=$(( ($hht * 100) / n ))
hthper=$(( ($hth * 100) / n ))
thhper=$(( ($thh * 100) / n ))
hhhper=$(( ($hhh * 100) / n ))
flipstore[hper]=$headper
flipsotre[tper]=$tailper
flipstore[hhper]=$hhper
flipstore[htper]=$htper
flipstore[thper]=$ttper
flipstore[ttper]=$thper
flipstore[tttper]=$tttper
flipstore[httper]=$httper
flipstore[thtper]=$thtper
flipstore[tthper]=$tthper
flipstore[hhtper]=$hhtper
flipstore[hthper]=$hthper
flipstore[thhper]=$thhper
flipstore[hhhper]=$hhhper
echo ${flipstore[@]}