Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils;
- const
- size = maxint div 2 div sizeof(integer);
- var
- x, y, F1, F2, temp: integer;
- i, j: integer;
- arr: array [1 .. size] of integer;
- f: boolean;
- choise: char;
- function REC(m, n: longint): longint;
- begin
- if m = 0 then
- begin
- REC := n + 1;
- inc(i);
- end;
- if (m > 0) and (n = 0) then
- begin
- REC := REC(m - 1, 1);
- inc(i);
- end
- else if (m > 0) and (n > 0) then
- begin
- REC := REC(m - 1, REC(m, n - 1));
- inc(i);
- end;
- end;
- function ITER(a, b: longint): longint;
- var
- t: integer;
- begin
- t := 1;
- arr[t] := a;
- repeat
- a := arr[t];
- dec(t);
- inc(j);
- if a = 0 then
- begin
- inc(b);
- inc(j);
- end
- else if b = 0 then
- begin
- inc(t);
- arr[t] := a - 1;
- b := b + 1;
- j := j + 2
- end
- else
- begin
- inc(t);
- arr[t] := a - 1;
- inc(t);
- arr[t] := a;
- dec(b);
- j := j + 3;
- end;
- if t > temp then
- begin
- temp := t;
- if temp > size then
- begin
- writeln('failure');
- f := false;
- end;
- end;
- until t = 0;
- ITER := b ;
- end;
- begin
- repeat
- f:=true;
- writeln('m = ');
- readln(x);
- writeln('n = ');
- readln(y);
- F2 := ITER(x, y);
- if f = true then
- begin
- writeln('iteration F = ', floattostr(F2));
- writeln(j,' steps');
- F1 := REC(x, y);
- writeln('recursion F = ', floattostr(F1));
- writeln(i, ' steps');
- end
- else
- writeln('OOPS');
- writeln ('repeat? 0 -no, 1 - yeah');
- readln(choise)
- until choise = '0';
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement