-
Notifications
You must be signed in to change notification settings - Fork 0
/
day15.mod
42 lines (36 loc) · 1009 Bytes
/
day15.mod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
MODULE Day15;
(*
Day #15: most hated day...
The simulation is so simple to run, but so slow on a poor 8-bit processor...
And to add more to it, I had to ressort to double precision floating point since 32-bits
integers aren't big enough...
*)
CONST MAXLONG = 2147483647.0D0;
VAR seedA : LONGINT;
PROCEDURE genA():LONGINT;
VAR tmp : LONGREAL;
BEGIN
tmp := DOUBLE(seedA) * 16807.0D0;
seedA := LONG(tmp - DOUBLE(LONG(tmp / MAXLONG)) * MAXLONG);
RETURN seedA;
END genA;
VAR seedB : LONGINT;
PROCEDURE genB():LONGINT;
VAR tmp : LONGREAL;
BEGIN
tmp := DOUBLE(seedB) * 48271.0D0;
seedB := LONG(tmp - DOUBLE(LONG(tmp / MAXLONG)) * MAXLONG);
RETURN seedB;
END genB;
VAR count, i, n : CARDINAL;
a, b : LONGINT;
BEGIN
seedA := 783L; seedB := 325L;
count := 0;
FOR i:=1 TO 500 DO FOR n:=1 TO 1000 DO
REPEAT a := genA() UNTIL a MOD 4L = 0L;
REPEAT b := genB() UNTIL b MOD 8L = 0L;
IF a MOD 65536L = b MOD 65536L THEN INC(count) END;
END END;
WRITELN(count)
END Day15.