Monty Hall problem: Difference between revisions

Content added Content deleted
(→‎{{header|bash}}: Marked incorrect as you need to add the comparison of the two strategies of the player to the simulation.)
Line 318: Line 318:


=={{header|bash}}==
=={{header|bash}}==
{{incorrect|bash|Please add the comparison of the two strategies of the player - always switching versus always sticking with an initial guess to the simulation.}}
{{works with|bash|2.x| and most bash-compatible unix shells}}
{{works with|bash|2.x| and most bash-compatible unix shells}}
<lang bash>
<lang bash>
Line 387: Line 386:
current_round=$[$current_round+1]
current_round=$[$current_round+1]
done
done

# Changed this summary message to indicate "always stay" vs. "always switch"
echo
echo
echo "Wins: $num_win, Losses: $num_lose"
echo "Wins (switch to remaining door): $num_win"
echo "Losses (stick to first choice): $num_lose"
exit 0
exit 0
</lang>
</lang>
Line 407: Line 409:
Player chooses #2. Host opens #3 (prize is behind #1) Switch from 2 to 1: WIN.
Player chooses #2. Host opens #3 (prize is behind #1) Switch from 2 to 1: WIN.


Wins: 6, Losses: 4
Wins (switch to remaining door): 6
Losses (stick to first choice): 4



$ ./monty_hall_problem.sh 10 5
$ ./monty_hall_problem.sh 10 5
Line 418: Line 422:
Player chooses #5. Host opens all except #7 and #5. (prize is behind #7) Switch from 5 to 7: WIN.
Player chooses #5. Host opens all except #7 and #5. (prize is behind #7) Switch from 5 to 7: WIN.


Wins: 4, Losses: 1
Wins (switch to remaining door): 4
Losses (stick to first choice): 1



$ ./monty_hall_problem.sh 3 1000
$ ./monty_hall_problem.sh 3 1000
Line 433: Line 439:
Player chooses #3. Host opens #1 (prize is behind #2) Switch from 3 to 2: WIN.
Player chooses #3. Host opens #1 (prize is behind #2) Switch from 3 to 2: WIN.


Wins: 655, Losses: 345
Wins (switch to remaining door): 655
Losses (stick to first choice): 345
</pre>
</pre>