Pascal - gregorymorrison/euler1 GitHub Wiki

It took me maybe a half hour to write Euler1 in Pascal, a language that I really know nothing about besides that it was supposedly designed as a teaching language way back in 1970. It feels a little stilted in its verbosity, its explicit declarations of everything, and its absurdly small integer type (32,767). Still, I can't complain given that it didn't take me that long to write this:

program Euler1(output);
{ Euler1 in Pascal }

Function Euler(size: integer) : LongInt;
    var i : integer;
Begin
    Euler := 0;
    For i := 0 to size do
        If (i mod 3 = 0) or (i mod 5 = 0) then
            Euler := Euler + i;
End;

var
    result : LongInt;
Begin
    result := Euler(999);
    writeln( result );
end.

To run on Fedora, yum-install fpc, the compiler Free Pascal. Then compile and execute (ignore the irrelevant compiler output):

$ fpc euler1.pscl
Free Pascal Compiler version 2.4.2 [2011/02/09] for i386
Copyright (c) 1993-2010 by Florian Klaempfl
Target OS: Linux for i386
Compiling euler1.pscl
Linking euler1
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
17 lines compiled, 0.2 sec 
$ ./euler1
233168