Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,45 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Nim is
|
||||
subtype Token_Range is Positive range 1 .. 3;
|
||||
|
||||
package TIO renames Ada.Text_IO;
|
||||
package Token_IO is new TIO.Integer_IO(Token_Range);
|
||||
|
||||
procedure Get_Tokens(remaining : in Natural; how_many : out Token_Range) is
|
||||
begin
|
||||
loop
|
||||
TIO.Put("How many tokens would you like to take? ");
|
||||
begin
|
||||
Token_IO.Get(TIO.Standard_Input, how_many);
|
||||
exit when how_many < remaining;
|
||||
raise Constraint_Error;
|
||||
exception
|
||||
when TIO.Data_Error | Constraint_Error =>
|
||||
if not TIO.End_Of_Line(TIO.Standard_Input) then
|
||||
TIO.Skip_Line(TIO.Standard_Input);
|
||||
end if;
|
||||
TIO.Put_Line("Invalid input.");
|
||||
end;
|
||||
end loop;
|
||||
end;
|
||||
|
||||
tokens : Natural := 12;
|
||||
how_many : Token_Range;
|
||||
begin
|
||||
loop
|
||||
TIO.Put_Line(tokens'Img & " tokens remain.");
|
||||
-- no exit condition here: human cannot win.
|
||||
Get_Tokens(tokens, how_many);
|
||||
TIO.Put_Line("Human takes" & how_many'Img & " tokens.");
|
||||
tokens := tokens - how_many;
|
||||
-- computer's turn: take the remaining N tokens to amount to 4.
|
||||
how_many := tokens mod 4;
|
||||
TIO.Put_Line("Computer takes" & how_many'Img & " tokens.");
|
||||
tokens := tokens - how_many;
|
||||
Ada.Text_IO.New_Line;
|
||||
exit when tokens = 0;
|
||||
end loop;
|
||||
|
||||
TIO.Put_Line("Computer won!");
|
||||
end Nim;
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. NIM-GAME.
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 MONTON PIC 99 VALUE 12.
|
||||
01 LLEVAR PIC 9 VALUE 0.
|
||||
01 TEMP PIC 9.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
PERFORM UNTIL MONTON = 0
|
||||
DISPLAY "There are " MONTON " tokens remaining. How many"
|
||||
"would you like to take? "
|
||||
ACCEPT LLEVAR
|
||||
PERFORM UNTIL LLEVAR > 0 AND LLEVAR < 4
|
||||
DISPLAY "You must take 1, 2, or 3 tokens. How many"
|
||||
"would you like to take "
|
||||
ACCEPT LLEVAR
|
||||
END-PERFORM
|
||||
COMPUTE TEMP = 4 - LLEVAR
|
||||
DISPLAY "On my turn I will take " TEMP " token(s)."
|
||||
SUBTRACT 4 FROM MONTON
|
||||
END-PERFORM
|
||||
DISPLAY " "
|
||||
DISPLAY "I got the last token. I win! Better luck next time."
|
||||
STOP RUN.
|
||||
Loading…
Add table
Add a link
Reference in a new issue