adventofcode/2020/5/find2.pas
2022-12-01 21:02:00 +01:00

53 lines
826 B
ObjectPascal

PROGRAM Hello;
USES
URadixSort;
VAR
filein : text;
mychar : char;
myseat, column, row, pass, i, n : integer;
seats : array[0..1023] of LongInt;
BEGIN
myseat := 0;
column := 0;
row := 0;
i := 0;
assign(filein, 'input');
reset(filein);
repeat begin
read(filein, mychar);
case mychar of
'F': row := row shl 1;
'B': row := (row shl 1) or 1;
'L': column := column shl 1;
'R': column := (column shl 1) or 1;
otherwise begin
pass := row * 8 + column;
seats[i] := pass;
i := i + 1;
row := 0;
column := 0;
end
end;
end;
until eof(filein);
close(filein);
(* Thank god the wiki for this *)
RadixSort(seats);
for n := 1 to i do
begin
if seats[n] <> seats[n - 1] + 1 then
myseat := seats[n] - 1
end;
writeln('Your seat is ', myseat);
END.