Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,33 @@
SeedRandom[1234];
ClearAll[ComputerChoose, HumanChoose]
ComputerChoose[n_] := If[n < 18, RandomChoice[{1, 2, 3}], 21 - n]
HumanChoose[] := ChoiceDialog["How many?", {1 -> 1, 2 -> 2, 3 -> 3, "Quit" -> -1}]
runningtotal = 0;
whofirst = ChoiceDialog["Who goes first?", {"You" -> 1, "Computer" -> 2}];
While[runningtotal < 21,
If[whofirst == 1,
choice = HumanChoose[];
If[choice == -1, Break[]];
Print["You choose = ", choice];
runningtotal += choice;
Print["Running total = ", runningtotal];
If[runningtotal == 21, Print["You won!"]; Break[]];
choice = ComputerChoose[runningtotal];
Print["Computer choose = ", choice];
runningtotal += choice;
Print["Running total = ", runningtotal];
If[runningtotal == 21, Print["Computer won!"]; Break[]];
,
choice = ComputerChoose[runningtotal];
Print["Computer choose = ", choice];
runningtotal += choice;
Print["Running total = ", runningtotal];
If[runningtotal == 21, Print["Computer won!"]; Break[]];
choice = HumanChoose[];
If[choice == -1, Break[]];
Print["You choose = ", choice];
runningtotal += choice;
Print["Running total = ", runningtotal];
If[runningtotal == 21, Print["You won!"]; Break[]];
];
]