Hello,
I've tried entering the valladolid programming contest, just to see if 
pascal programs were still accepted.

See here: http://icpcres.ecs.baylor.edu/onlinejudge/index.php

And I find my simple program doesn't compile. Has anyone tried this 
before and knows how to deliver a workable piece of code. I'm using 
Lazarus and FPC 2.2.2 under Ubuntu of course, but there shouldn't be any 
significant changes with FPC 2.0.4.

See the program test (for the 3N+1 test) I sent at the end of this post:

If anyone can find what is wrong, and what should be done to correct it, 
thank you for your help,

Thierry.

 >> TEST PROGRAM
program Test1;

var
  i, j : integer; //input data
  k, l : integer; //interval
  m    : integer; //index
  maxCycles : integer; //max number of cycles for the interval
  Cycles: integer;

// This function computes the number of cycles for the 3N+1 algorithm.
function FindCycles(const value: integer):integer;
begin
  result := 1;
  if value > 1 then
  begin
    if (value mod 2) > 0 then
      result := 1+FindCycles(3*value+1)
    else
      result := 1+FindCycles(value div 2);
  end;
end;

// main program
begin
  repeat
    // get the input interval
    readln(i,j);
    k := i;
    l := j;
    if j<i then
    begin
      k := j;
      l := i;
    end;

    //iterating over each element
    maxCycles := 0;
    for m := k to l do
    begin
      Cycles := FindCycles( m);
      if Cycles > maxCycles then
        maxCycles := Cycles;
    end;

    //write the results
    writeln(i,' ',j,' ', maxCycles);

  until eof;
end.
                      
<< END OF TEST PROGRAM
_______________________________________________
Lazarus mailing list
[email protected]
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to