Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Recursion #61

Closed
zbyti opened this issue Oct 24, 2021 · 1 comment
Closed

[BUG] Recursion #61

zbyti opened this issue Oct 24, 2021 · 1 comment

Comments

@zbyti
Copy link
Collaborator

zbyti commented Oct 24, 2021

// spodziewany wynik to 3! i taki podaje Free Pascal

uses crt;

const
  size = 2; // od zera to size+1 elementow

var
  board   : array [0..size] of byte;
  i       : byte;
  counter : word = 0;

procedure generate(n: byte);
var
  i, tmp: byte;
begin

  if n = 0 then
    begin
      //for tmp in board do write(tmp); writeln;
      inc(counter);
    end
  else
    begin
      for i := 0 to n do begin
        tmp := board[i]; board[i] := board[n]; board[n] := tmp;
        generate(n-1);
        tmp := board[i]; board[i] := board[n]; board[n] := tmp;
      end;
    end;

end;

begin
  for i := 0 to size do board[i] := i;

  generate(size);

  writeln('liczba permutacji: ', counter);

  repeat until keypressed;
end.

tebe6502 added a commit that referenced this issue Oct 25, 2021
tebe6502 added a commit that referenced this issue Oct 25, 2021
tebe6502 added a commit that referenced this issue Oct 26, 2021
tebe6502 added a commit that referenced this issue Oct 26, 2021
@zbyti
Copy link
Collaborator Author

zbyti commented Oct 26, 2021

fix works! thx :]

@zbyti zbyti closed this as completed Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant