Compare commits

...

2 Commits

Author SHA1 Message Date
OMGOMG cbde4fcde4 make explicit what is alice's bet 2022-04-06 16:40:17 +02:00
OMGOMG 41040f18e7 some more stats 2022-04-06 00:25:08 +02:00
2 changed files with 15 additions and 6 deletions

View File

@ -1,5 +1,6 @@
#!/usr/bin/env bash
# Usage:
# ./play.bash
alice_sum=0
@ -11,13 +12,14 @@ round=0
# bob's hand is random
while read -r prize bob_bet
do
alice_bet=$prize
printf 'Runde %s: Premie er %s, Alice satser %s, Bob satser %s.\n' \
"$((++round))" "$prize" "$prize" "$bob_bet"
if ((prize > bob_bet))
"$((++round))" "$prize" "$alice_bet" "$bob_bet"
if ((alice_bet > bob_bet))
then
((alice_sum += prize))
printf 'Alice vinner %s!\n' "$prize"
elif ((bob_bet > prize))
elif ((bob_bet > alice_bet))
then
((bob_sum += prize))
printf 'Bob vinner %s!\n' "$prize"

View File

@ -1,10 +1,11 @@
#!/usr/bin/env bash
# Usage
# ./stats.bash
# or
# ./stats.bash NUM_SIMULATIONS
for ((i=0; i < ${1:-1000}; i++))
for ((i=0; i < ${1:-100}; i++))
do
./play.bash
done | awk '
@ -14,10 +15,16 @@ done | awk '
/^Uavgjort\.\.\.$/ {
tie++
}
/^[[:alnum:]]+: [[:digit:]]+$/ {
points[substr($1, 0, length($1) - 1)] += $2 # strip away exclamation mark
}
END {
for(i in win) {
printf "%s vant %d ganger.\n", i, (win[i] ? win[i] : 0)
for(i in points) {
printf "%s vant %d ganger med %d poeng totalt..\n",
i,
(win[i] ? win[i] : 0),
(points[i] ? points[i] : 0)
}
print "Det ble uavgjort", (tie ? tie : 0), "ganger."
}