Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-03

Valladolid Programming Contest simple test fails at compile?

12 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Thierry Coq

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

Reply by email

Mehmet Erol Sanliturk
to Thierry Coq: I've tried entering the valladolid programming contest, just to see if pascal programs…
pm Thierry Coq wrote 57 lines
>> 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 _______________________________________________

At until eof , there should be a file variable name as eof ( FN ) where FN may be

var FN : Text ;
or
var FN : File ... ;

Thank you very much .

Mehmet Erol Sanliturk

Reply by email

Mehmet Erol Sanliturk
to Mehmet Erol Sanliturk
pm Mehmet Erol Sanliturk wrote 66 lines
On Thursday 26 March 2009 05:16:32 pm Thierry Coq wrote: > >> 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 > _______________________________________________ At until eof , there should be a file variable name as eof ( FN ) where FN may be var FN : Text ; or var FN : File ... ;

I am sorry that the error is NOT the above .
I compiled the program . It is giving error to name result within function FindCycles as Identifier not found .

If a variable as
var result : integer ;

is defined it is compiled correctly with a warning

Function result does not seem to be set .

Insertion of statement

FindCycles := result ;

is removing warning statement .

Thank you very much .

Mehmet Erol Sanliturk

Reply by email

waldo kitty
to Mehmet Erol Sanliturk: At until eof , there should be a file variable name as eof ( FN ) where FN may be var FN…
Mehmet Erol Sanliturk wrote 5 lines
On Thursday 26 March 2009 05:16:32 pm Thierry Coq wrote: > > >> TEST PROGRAM > > program Test1;

[CHOMP]

Show quoted text 14 lines
> until eof; > end. > > << END OF TEST PROGRAM > _______________________________________________ > At until eof , there should be a file variable name as eof ( FN ) where FN may be var FN : Text ; or var FN : File ... ;

not only that, there's nothing that names and opens that file, either...

NOTE: NEW EMAIL ADDRESS!! _\/ (@@) Waldo Kitty, Waldo's Place USA __ooO_( )_Ooo_____________________ telnet://bbs.wpusa.dynip.com _|_____|_____|_____|_____|_____|_____ http://www.wpusa.dynip.com ____|_____|_____|_____|_____|_____|____ ftp://ftp.wpusa.dynip.com _|_Eat_SPAM_to_email_me!_YUM!__|_____ wkitty42 -at- windstream.net

Reply by email

Vincent Snijders
to waldo kitty
waldo kitty wrote 22 lines
Mehmet Erol Sanliturk wrote: > On Thursday 26 March 2009 05:16:32 pm Thierry Coq wrote: >> >> TEST PROGRAM >> >> program Test1; [CHOMP] >> until eof; >> end. >> >> << END OF TEST PROGRAM >> _______________________________________________ >> > > At until eof , there should be a file variable name as eof ( FN ) > where FN may be > > var FN : Text ; > or > var FN : File ... ; not only that, there's nothing that names and opens that file, either...

So, it must read from stdin, which seems a reasonable thing in contests.

Vincent

Reply by email

Thierry Coq
to Vincent Snijders

yes, it does read from standard input and output file. So there's no need to create textfiles. (It is possible to mention the input and output files in the program declaration such as : program test1(input, output).

Adding {$MODE OBJFPC}on Joshyfun's suggestion solved the compiler error.

Now I have an time exceeded issue, which doesn't seem too likely as I implemented a rather standard solution. I wonder if the "repeat until eof" or "while eof do" is not the issue...the program would be waiting endlessly for another input which isn't coming. Usually one checks the input file is empty by using eof. Is there another way recommended for these contests?

Thanks all of you for the help!
Thierry

Vincent Snijders wrote 40 lines
waldo kitty schreef: > Mehmet Erol Sanliturk wrote: > >> On Thursday 26 March 2009 05:16:32 pm Thierry Coq wrote: >> >>> >> TEST PROGRAM >>> >>> program Test1; >>> > [CHOMP] > >>> until eof; >>> end. >>> >>> << END OF TEST PROGRAM >>> _______________________________________________ >>> >>> >> At until eof , there should be a file variable name as eof ( FN ) >> where FN may be >> >> var FN : Text ; >> or >> var FN : File ... ; >> > not only that, there's nothing that names and opens that file, either... > > So, it must read from stdin, which seems a reasonable thing in contests. Vincent _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

JoshyFun
to Thierry Coq

Hello Thierry,

Friday, March 27, 2009, 6:23:42 PM, you wrote:

TC> Adding {$MODE OBJFPC}on Joshyfun's suggestion solved the compiler error.

TC> Now I have an time exceeded issue, which doesn't seem too likely as I TC> implemented a rather standard solution. I wonder if the "repeat until TC> eof" or "while eof do" is not the issue...the program would be waiting TC> endlessly for another input which isn't coming. Usually one checks the TC> input file is empty by using eof. Is there another way recommended for TC> these contests?

I have none experience on the contest scene, but eof in the stdin looks nonsense for me when you input data using the keyboard, 'cos after the first line (readln) the eof is a fact ;)

"eof or empty line" seems to be more logical to me. You should check how the program works if you feed stdin from a file:

test.exe < file.txt

Best regards, JoshyFun

Reply by email

Mehmet Erol Sanliturk
to JoshyFun
pm JoshyFun wrote 12 lines
Hello Thierry, TC>Is there another way recommended for TC> these contests? I have none experience on the contest scene, but eof in the stdin looks nonsense for me when you input data using the keyboard, 'cos after the first line (readln) the eof is a fact ;) "eof or empty line" seems to be more logical to me. You should check how the program works if you feed stdin from a file: test.exe < file.txt

Additionally :

Between _readln _ and _until eof_ statements , there should be an if statement
such as

if not eof
then
begin
{ statements between readln and until eof ... }
end ;

because when EOF is seen those stements should not be executed because there is no valid input at that state .

Thank you very much .

Mehmet Erol Sanliturk

Reply by email

Thierry Coq
to Mehmet Erol Sanliturk

Thank you guys,

The code works perfectly with the keyboard (it won't stop which is normal) or when I feed it an input file (it stops fine after a few milliseconds of work). Eof or Eoln doesn't seem to be the issue. I've tried another problem where the input finishes by the "quit" word, and I have the same issue.
FYI, I've attached the two tests for problem 100 (test3) and problem 101 (test4).

Has somebody here delivered a successful pascal program to the UVa online judge: http://icpcres.ecs.baylor.edu/onlinejudge/index.php ?

Test problem 100:
http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36

Test problem 101:
http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=37

Best regards,
Thierry,

Mehmet Erol Sanliturk wrote 44 lines
On Friday 27 March 2009 08:08:20 pm JoshyFun wrote: > Hello Thierry, > TC>Is there another way recommended for > TC> these contests? > > I have none experience on the contest scene, but eof in the stdin > looks nonsense for me when you input data using the keyboard, 'cos > after the first line (readln) the eof is a fact ;) > > "eof or empty line" seems to be more logical to me. You should check > how the program works if you feed stdin from a file: > > test.exe < file.txt > Additionally : Between _readln _ and _until eof_ statements , there should be an if statement such as if not eof then begin { statements between readln and until eof ... } end ; because when EOF is seen those stements should not be executed because there is no valid input at that state . Thank you very much . Mehmet Erol Sanliturk _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed... Name: test3.lpr
Url: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090328/66ce6d4b/attachment.pl -------------- next part --------------
An embedded and charset-unspecified text was scrubbed... Name: test4.lpr
Url: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090328/66ce6d4b/attachment-0001.pl

Reply by email

Vincent Snijders
to Thierry Coq
Thierry Coq wrote 7 lines
Thank you guys, Has somebody here delivered a successful pascal program to the UVa online judge: http://icpcres.ecs.baylor.edu/onlinejudge/index.php ? Test problem 100: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36

I just succesfully submitted and passed this test problem. See attachment for source code.

Vincent
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed... Name: the3nplus1problem.pas
Url: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090328/73ad11b0/attachment.pl

Reply by email

Thierry Coq
to Vincent Snijders

Hello,

I've passed successfully passed both tests 3N+1 and 101 Blocks.

3N+1 is similar to VIncent's solution.

101 Blocks solution is attached here. Mode ObjFPC is accepted which means we can use our modern pascal dialects. I was afraid it wouldn't be possible.

Thanks.

Thierry

Vincent Snijders wrote 19 lines
Thierry Coq schreef: > Thank you guys, > Has somebody here delivered a successful pascal program to the UVa > online judge: http://icpcres.ecs.baylor.edu/onlinejudge/index.php ? > > Test problem 100: > http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36 > I just succesfully submitted and passed this test problem. See attachment for source code. Vincent ------------------------------------------------------------------------ _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed... Name: test101_16_asobj.lpr
Url: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090329/a77c8ab8/attachment.pl

Reply by email