Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.66 KB | None | 0 0
  1. program Project2;
  2.  
  3. {$APPTYPE CONSOLE}
  4. {$R *.res}
  5.  
  6. uses
  7.   System.SysUtils;
  8.  
  9. const
  10.   size = maxint div 2 div sizeof(integer);
  11.  
  12. var
  13.   x, y, F1, F2, temp: integer;
  14.   i, j: integer;
  15.   arr: array [1 .. size] of integer;
  16.   f: boolean;
  17.   choise: char;
  18.  
  19. function REC(m, n: longint): longint;
  20. begin
  21.   if m = 0 then
  22.   begin
  23.     REC := n + 1;
  24.     inc(i);
  25.   end;
  26.   if (m > 0) and (n = 0) then
  27.   begin
  28.     REC := REC(m - 1, 1);
  29.     inc(i);
  30.   end
  31.   else if (m > 0) and (n > 0) then
  32.   begin
  33.     REC := REC(m - 1, REC(m, n - 1));
  34.     inc(i);
  35.   end;
  36. end;
  37.  
  38. function ITER(a, b: longint): longint;
  39. var
  40.   t: integer;
  41. begin
  42.   t := 1;
  43.   arr[t] := a;
  44.   repeat
  45.     a := arr[t];
  46.     dec(t);
  47.     inc(j);
  48.     if a = 0 then
  49.     begin
  50.       inc(b);
  51.       inc(j);
  52.     end
  53.     else if b = 0 then
  54.     begin
  55.       inc(t);
  56.       arr[t] := a - 1;
  57.       b := b + 1;
  58.       j := j + 2
  59.     end
  60.     else
  61.     begin
  62.       inc(t);
  63.       arr[t] := a - 1;
  64.       inc(t);
  65.       arr[t] := a;
  66.       dec(b);
  67.       j := j + 3;
  68.     end;
  69.     if t > temp then
  70.     begin
  71.       temp := t;
  72.       if temp > size then
  73.       begin
  74.         writeln('failure');
  75.         f := false;
  76.       end;
  77.     end;
  78.   until t = 0;
  79.   ITER := b ;
  80. end;
  81.  
  82. begin
  83. repeat
  84.   f:=true;
  85.   writeln('m = ');
  86.   readln(x);
  87.   writeln('n = ');
  88.   readln(y);
  89.   F2 := ITER(x, y);
  90.   if f = true then
  91.   begin
  92.     writeln('iteration F = ', floattostr(F2));
  93.     writeln(j,' steps');
  94.     F1 := REC(x, y);
  95.     writeln('recursion F = ', floattostr(F1));
  96.     writeln(i, '  steps');
  97.   end
  98.   else
  99.     writeln('OOPS');
  100.     writeln ('repeat? 0 -no, 1 - yeah');
  101.     readln(choise)
  102.  until choise = '0';
  103.  
  104. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement