Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Nim-game/AWK/nim-game.awk
Normal file
24
Task/Nim-game/AWK/nim-game.awk
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# syntax: GAWK -f NIM_GAME.AWK
|
||||
BEGIN {
|
||||
tokens = 12
|
||||
printf("Nim game - using %d tokens\n",tokens)
|
||||
while (tokens > 0) {
|
||||
for (;;) {
|
||||
printf("how many tokens 1-3? ")
|
||||
getline ans
|
||||
if (ans ~ /^[123]$/) {
|
||||
tokens -= ans
|
||||
prn("player")
|
||||
break
|
||||
}
|
||||
print("invalid input, try again")
|
||||
}
|
||||
tokens -= ans = tokens % 4
|
||||
prn("computer")
|
||||
}
|
||||
print("computer wins")
|
||||
exit(0)
|
||||
}
|
||||
function prn(who) {
|
||||
printf("%s takes %d token%s; there are %d remaining\n",who,ans,(ans==1)?"":"s",tokens)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue