PnnK

gametheoryEGE_pascalABC

Aug 21st, 2021 (edited)
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.99 KB | None | 0 0
  1. //Решение 19 задания нового формата
  2. function f(S, turn : integer) : boolean;
  3. begin
  4.   if (s>=40) and (turn <> 2) then
  5.     result := False
  6.   else if (s<40) and (turn = 2) then
  7.     result := False
  8.   else if (s>=40) and (turn = 2) then
  9.     result := True
  10.   else if (turn mod 2 = 0) then //Для решения задачи с неудачным ходом достаточно не проверять ходы на чётность
  11.                                 //И вызывать новых ход всегда с "or".
  12.     result := f(S*2, turn+1) and f(S+1, turn+1) and f(S+4, turn+1)
  13.   else if (turn mod 2 <> 0) then
  14.     result := f(S*2, turn+1) or f(S+1, turn+1) or f(S+4, turn+1);
  15. end;
  16.  
  17. //Решение 20 задания
  18. function g(S, turn : integer) : boolean;
  19. begin
  20.   if (s>=40) and (turn <> 3) then
  21.     result := False
  22.   else if (s<40) and (turn = 3) then
  23.     result := False
  24.   else if (s>=40) and (turn = 3) then
  25.     result := True
  26.   else if (turn mod 2 <> 0) then
  27.     result := g(S*2, turn+1) and g(S+1, turn+1) and g(S+4, turn+1)
  28.   else if (turn mod 2 = 0) then
  29.     result := g(S*2, turn+1) or g(S+1, turn+1) or g(S+4, turn+1);
  30. end;
  31. //Решение 21 задания (лишь с той оговоркой, что нужно отсеять варианты условием not f(S,0))
  32. function h(S, turn : integer) : boolean;
  33. begin
  34.   if (s>=40) and ((turn = 4) or (turn = 2)) then
  35.     result := True
  36.   else if (s>=40) and (turn <> 4) then
  37.     result := False
  38.   else if (s<40) and (turn = 4) then
  39.     result := False
  40.   else if (turn mod 2 = 0) then
  41.     result := h(S*2, turn+1) and h(S+1, turn+1) and h(S+4, turn+1)
  42.   else if (turn mod 2 <> 0) then
  43.     result := h(S*2, turn+1) or h(S+1, turn+1) or h(S+4, turn+1);
  44. end;
  45.  
  46.  
  47. begin
  48.     for var s := 0 to 40 do
  49.     if f(S,0) then
  50.       print('19:', S);
  51.  
  52.     for var s := 0 to 40 do
  53.     if g(S,0) then
  54.       print('20:', S);
  55.  
  56.     for var s := 0 to 40 do
  57.     if h(S,0) and not f(S,0) then
  58.       print('21:', S);
  59. end.
Add Comment
Please, Sign In to add comment