"Fossies" - the Fresh Open Source Software Archive

Member "gpc-20060325/p/test/ancestor.pas" (31 Oct 2002, 672 Bytes) of package /linux/misc/old/gpc-20060325.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) delphi source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 { FLAG -Dwallclock=42 }
    2 
    3 program ancestor(output);
    4 {R.W.Floyd: 'Ancestor', Comm.ACM 6-62 and 3-63, Alg.96}
    5   const n = 20;
    6   var i,j,k: integer;
    7       r: array [1..n, 1..n] of boolean;
    8 begin { r[i,j] = "i is a parent of j"}
    9   for i := 1 to n do
   10     for j := 1 to n do r[i,j] := false;
   11   for i := 1 to n do
   12     if i mod 10 <> 0 then r[i,i+1] := true;
   13   writeln(wallclock);
   14   for i := 1 to n do
   15     for j := 1 to n do
   16       if r[j,i] then
   17         for k := 1 to n do
   18           if r[i,k] then r[j,k] := true;
   19   writeln(wallclock);
   20   for i := 1 to n do
   21   begin write(' ');
   22     for j := 1 to n do write(chr(ord(r[i,j])+ord('0')));
   23     writeln
   24   end ;
   25   writeln(wallclock)
   26 end .