Nim game

You are encouraged to solve this task according to the task description, using any language you may know.
Nim is a simple game where the second player ─── if they know the trick ─── will always win.



The game has only 3 rules:

   start with   12   tokens
   each player takes   1,  2,  or  3   tokens in turn
  the player who takes the last token wins.


To win every time,   the second player simply takes 4 minus the number the first player took.   So if the first player takes 1,   the second takes 3 ─── if the first player takes 2,   the second should take 2 ─── and if the first player takes 3,   the second player will take 1.



Task

Design a simple Nim game where the human player goes first, and the computer always wins. The game should enforce the rules.




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;