Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Решение 19 задания нового формата
- function f(S, turn : integer) : boolean;
- begin
- if (s>=40) and (turn <> 2) then
- result := False
- else if (s<40) and (turn = 2) then
- result := False
- else if (s>=40) and (turn = 2) then
- result := True
- else if (turn mod 2 = 0) then //Для решения задачи с неудачным ходом достаточно не проверять ходы на чётность
- //И вызывать новых ход всегда с "or".
- result := f(S*2, turn+1) and f(S+1, turn+1) and f(S+4, turn+1)
- else if (turn mod 2 <> 0) then
- result := f(S*2, turn+1) or f(S+1, turn+1) or f(S+4, turn+1);
- end;
- //Решение 20 задания
- function g(S, turn : integer) : boolean;
- begin
- if (s>=40) and (turn <> 3) then
- result := False
- else if (s<40) and (turn = 3) then
- result := False
- else if (s>=40) and (turn = 3) then
- result := True
- else if (turn mod 2 <> 0) then
- result := g(S*2, turn+1) and g(S+1, turn+1) and g(S+4, turn+1)
- else if (turn mod 2 = 0) then
- result := g(S*2, turn+1) or g(S+1, turn+1) or g(S+4, turn+1);
- end;
- //Решение 21 задания (лишь с той оговоркой, что нужно отсеять варианты условием not f(S,0))
- function h(S, turn : integer) : boolean;
- begin
- if (s>=40) and ((turn = 4) or (turn = 2)) then
- result := True
- else if (s>=40) and (turn <> 4) then
- result := False
- else if (s<40) and (turn = 4) then
- result := False
- else if (turn mod 2 = 0) then
- result := h(S*2, turn+1) and h(S+1, turn+1) and h(S+4, turn+1)
- else if (turn mod 2 <> 0) then
- result := h(S*2, turn+1) or h(S+1, turn+1) or h(S+4, turn+1);
- end;
- begin
- for var s := 0 to 40 do
- if f(S,0) then
- print('19:', S);
- for var s := 0 to 40 do
- if g(S,0) then
- print('20:', S);
- for var s := 0 to 40 do
- if h(S,0) and not f(S,0) then
- print('21:', S);
- end.
Add Comment
Please, Sign In to add comment