Skip to content

Commit ad82a93

Browse files
committed
FreePascal raffler
1 parent 128a34f commit ad82a93

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

jkva-freepascal/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM debian:stable
2+
3+
MAINTAINER job@jobva.nl
4+
5+
ENV LANG C.UTF-8
6+
7+
# Update deps
8+
RUN apt-get update
9+
10+
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y fp-compiler-3.0.0
11+
12+
# Create working dir
13+
RUN mkdir -p /var/app
14+
COPY . /var/app
15+
WORKDIR /var/app
16+
17+
# Run raffler
18+
ADD raffler.pas /var/app/
19+
CMD ["fpc", "/var/app/raffler.pas"]
20+
CMD ["./raffler", "/var/names.txt"]

jkva-freepascal/raffler.pas

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
program Raffler;
2+
3+
{$IFDEF FPC}
4+
{$MODE OBJFPC}
5+
{$I+}
6+
{$ENDIF}
7+
8+
uses
9+
SysUtils;
10+
11+
var
12+
names : TextFile;
13+
winner: String;
14+
count : Integer = 0;
15+
i : Integer = 0;
16+
rnd : Integer = 0;
17+
18+
begin
19+
if (ParamCount = 0) then begin
20+
writeln('ERROR: No filename supplied.');
21+
halt;
22+
end;
23+
24+
Assign(names, ParamStr(1));
25+
26+
try
27+
reset(names);
28+
while not eof(names) do begin
29+
readln(names, winner);
30+
inc(count);
31+
end;
32+
except
33+
on E: EInOutError do begin
34+
writeln('ERROR: handling input: ', E.Message);
35+
halt;
36+
end;
37+
end;
38+
39+
if (count = 0) then begin
40+
writeln('ERROR: No names in file.');
41+
halt;
42+
end;
43+
44+
Randomize;
45+
rnd := Random(count);
46+
47+
reset(names);
48+
49+
while i <= rnd do begin
50+
readln(names, winner);
51+
inc(i);
52+
end;
53+
54+
CloseFile(names);
55+
56+
writeln('We have a winner: ', winner);
57+
end.

0 commit comments

Comments
 (0)