Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreePascal raffler #161

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions jkva-freepascal/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM debian:stable

MAINTAINER [email protected]

ENV LANG C.UTF-8

# Update deps
RUN apt-get update

RUN DEBIAN_FRONTEND=noninteractive apt-get install -y fp-compiler-3.0.0

# Create working dir
RUN mkdir -p /var/app
COPY . /var/app
WORKDIR /var/app

# Run raffler
RUN fpc /var/app/raffler.pas
CMD ["/var/app/raffler", "/var/names.txt"]
57 changes: 57 additions & 0 deletions jkva-freepascal/raffler.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
program Raffler;

{$IFDEF FPC}
{$MODE OBJFPC}
{$I+}
{$ENDIF}

uses
SysUtils;

var
names : TextFile;
winner: String;
count : Integer = 0;
i : Integer = 0;
rnd : Integer = 0;

begin
if (ParamCount = 0) then begin
writeln('ERROR: No filename supplied.');
halt;
end;

Assign(names, ParamStr(1));

try
reset(names);
while not eof(names) do begin
readln(names, winner);
inc(count);
end;
except
on E: EInOutError do begin
writeln('ERROR: handling input: ', E.Message);
halt;
end;
end;

if (count = 0) then begin
writeln('ERROR: No names in file.');
halt;
end;

Randomize;
rnd := Random(count);

reset(names);

while i <= rnd do begin
readln(names, winner);
inc(i);
end;

CloseFile(names);

writeln('We have a winner: ', winner);
end.