-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
75 lines (62 loc) · 1.88 KB
/
Copy pathmain.js
File metadata and controls
75 lines (62 loc) · 1.88 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"use strict";
import {log} from "./log.js";
import {enumerate} from "./Enumerate/enumerator.js";
import {unparse, parseArea} from "./parser.js";
import {LOG, AREA} from "./config.js";
// Initialize
// ================================================================
const enumArea = AREA.ENABLED ? parseArea(AREA.VALUE) : [];
const count = {
total: 0,
halted: 0,
nonhalted: 0,
holdout: 0
}
let record = 0;
function logProgram(status, program, ...arg) {
const logArray = [];
if (LOG.SHOW_STATUS) logArray.push(status);
logArray.push(unparse(program));
logArray.push(...arg);
log(...logArray);
}
// Main function
// ================================================================
const start = performance.now();
for (const [halted, program, state] of enumerate(enumArea)) {
if (halted === true) {
const score = state.vars.reduce(
(best, value) => Math.max(best, value ?? 0),
0
);
if (score > record) {
if (LOG.CHAMPION)
logProgram("Champion:", program, "Score:", score);
record = score;
}
else {
if (LOG.HALTED)
logProgram("Halted:", program);
}
count.halted++
}
else if (halted === false) {
if (LOG.NONHALTED)
logProgram("Nonhalted:", program);
count.nonhalted++;
}
else if (halted === null) {
if (LOG.HOLDOUT)
logProgram("Holdout:", program);
count.holdout++;
}
count.total++;
}
const end = performance.now();
// Results
// ================================================================
log("Total:", count.total);
log("Halted:", count.halted);
log("Nonhalted:", count.nonhalted);
log("Holdout:", count.holdout);
log(`Time: ${((end - start) / 1_000).toFixed(3)}s`);