Nim game: Difference between revisions

Content added Content deleted
(+add Pike)
(added Arturo implementation)
Line 560: Line 560:
This one-liner demonstrates the 240 character line limit. The program has been crafted to be exactly 244 characters long. The last 4 characters HEAP will be truncated from the last statement in the line. The HEAP variable is optional in the out-most NEXT statement so the program still runs correctly.
This one-liner demonstrates the 240 character line limit. The program has been crafted to be exactly 244 characters long. The last 4 characters HEAP will be truncated from the last statement in the line. The HEAP variable is optional in the out-most NEXT statement so the program still runs correctly.
<lang ApplesoftBasic>0ST$(0)="YOU MUST TAKE 1, 2, OR 3 TOKENS.":FORHEAP=12TO1STEP-4:PRINT"THERE ARE "HEAP" TOKENS REMAINING.":FORI=0TO1:INPUT"HOW MANY WOULD YOU LIKE TO TAKE?";T%:I=T%>0ANDT%<4:PRINTST$(I):NEXTI:PRINT"ON MY TURN I WILL TAKE "4-T%" TOKENS.":NEXTHEAP</lang>
<lang ApplesoftBasic>0ST$(0)="YOU MUST TAKE 1, 2, OR 3 TOKENS.":FORHEAP=12TO1STEP-4:PRINT"THERE ARE "HEAP" TOKENS REMAINING.":FORI=0TO1:INPUT"HOW MANY WOULD YOU LIKE TO TAKE?";T%:I=T%>0ANDT%<4:PRINTST$(I):NEXTI:PRINT"ON MY TURN I WILL TAKE "4-T%" TOKENS.":NEXTHEAP</lang>

=={{header|Arturo}}==

<lang rebol>total: 12
while ø [
tk: 0
print "YOUR turn:"
while [not? contains? 1..3 tk: <= to :integer input "How many tokens will you take? (1-3) "][]
total: total-tk
print [total "tokens remaining\n"]

print ["COMPUTER's turn:"]
print ["taking:" 4-tk]
total: total-(4-tk)
print [total "tokens remaining\n"]
if total=0 [
print "COMPUTER won. :)"
break
]
]</lang>

{{out}}

<pre>YOUR turn:
How many tokens will you take? (1-3) 3
9 tokens remaining
COMPUTER's turn:
taking: 1
8 tokens remaining
YOUR turn:
How many tokens will you take? (1-3) 2
6 tokens remaining
COMPUTER's turn:
taking: 2
4 tokens remaining
YOUR turn:
How many tokens will you take? (1-3) 1
3 tokens remaining
COMPUTER's turn:
taking: 3
0 tokens remaining
COMPUTER won. :)</pre>


=={{header|AsciiDots}}==
=={{header|AsciiDots}}==