eyeling 1.19.4 → 1.19.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HANDBOOK.md +48 -89
- package/examples/deck/extra.md +169 -0
- package/examples/extra/collatz-1000.js +138 -0
- package/examples/extra/control-system.js +68 -0
- package/examples/extra/deep-taxonomy-100000.js +95 -0
- package/examples/extra/delfour.js +110 -0
- package/examples/extra/euler-identity.js +41 -0
- package/examples/extra/fibonacci.js +81 -0
- package/examples/extra/goldbach-1000.js +112 -0
- package/examples/extra/gps.js +274 -0
- package/examples/extra/kaprekar-6174.js +112 -0
- package/examples/extra/matrix-mechanics.js +69 -0
- package/examples/extra/odrl-dpv-ehds-risk-ranked.js +255 -0
- package/examples/extra/output/collatz-1000.txt +18 -0
- package/examples/extra/output/control-system.txt +14 -0
- package/examples/extra/output/deep-taxonomy-100000.txt +15 -0
- package/examples/extra/output/delfour.txt +20 -0
- package/examples/extra/output/euler-identity.txt +12 -0
- package/examples/extra/output/fibonacci.txt +21 -0
- package/examples/extra/output/goldbach-1000.txt +17 -0
- package/examples/extra/output/gps.txt +33 -0
- package/examples/extra/output/kaprekar-6174.txt +17 -0
- package/examples/extra/output/matrix-mechanics.txt +14 -0
- package/examples/extra/output/odrl-dpv-ehds-risk-ranked.txt +48 -0
- package/examples/extra/output/path-discovery.txt +28 -0
- package/examples/extra/output/pn-junction-tunneling.txt +15 -0
- package/examples/extra/output/polynomial.txt +20 -0
- package/examples/extra/output/sudoku.txt +47 -0
- package/examples/extra/output/transistor-switch.txt +16 -0
- package/examples/extra/path-discovery.js +45114 -0
- package/examples/extra/pn-junction-tunneling.js +69 -0
- package/examples/extra/polynomial.js +181 -0
- package/examples/extra/sudoku.js +330 -0
- package/examples/extra/transistor-switch.js +93 -0
- package/examples/fibonacci.n3 +2 -0
- package/examples/output/fibonacci.n3 +1 -0
- package/eyeling.js +49 -45
- package/lib/engine.js +49 -45
- package/package.json +3 -2
- package/test/extra.test.js +100 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Kaprekar 6174 exploration over all admissible four-digit starts.
|
|
6
|
+
* The script records traces, a convergence histogram, and a few representative witnesses.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
function digits4(n) {
|
|
10
|
+
return [Math.floor(n / 1000) % 10, Math.floor(n / 100) % 10, Math.floor(n / 10) % 10, n % 10];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function sort4(digits, descending) {
|
|
14
|
+
digits.sort((a, b) => (descending ? b - a : a - b));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function build4(d) {
|
|
18
|
+
return d[0] * 1000 + d[1] * 100 + d[2] * 10 + d[3];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function hasTwoDistinctDigits(n) {
|
|
22
|
+
const d = digits4(n);
|
|
23
|
+
for (let i = 1; i < 4; i += 1) if (d[i] !== d[0]) return true;
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function kaprekarStep(n) {
|
|
28
|
+
const hi = digits4(n);
|
|
29
|
+
const lo = [...hi];
|
|
30
|
+
sort4(hi, true);
|
|
31
|
+
sort4(lo, false);
|
|
32
|
+
return build4(hi) - build4(lo);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function kaprekarTrace(start, cap) {
|
|
36
|
+
const out = [];
|
|
37
|
+
let cur = start;
|
|
38
|
+
while (out.length < cap) {
|
|
39
|
+
out.push(cur);
|
|
40
|
+
if (cur === 6174) break;
|
|
41
|
+
cur = kaprekarStep(cur);
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function fmt4(n) {
|
|
47
|
+
return String(n).padStart(4, '0');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Explore the full start space and then print a compact convergence summary.
|
|
51
|
+
function main() {
|
|
52
|
+
let validStarts = 0;
|
|
53
|
+
let repdigits = 0;
|
|
54
|
+
let maxIterations = 0;
|
|
55
|
+
let worstCaseStarts = 0;
|
|
56
|
+
const hist = new Array(8).fill(0);
|
|
57
|
+
let worstTrace = [];
|
|
58
|
+
const leadingTrace = kaprekarTrace(2111, 16);
|
|
59
|
+
let allReach = true;
|
|
60
|
+
let boundOk = true;
|
|
61
|
+
|
|
62
|
+
for (let start = 0; start <= 9999; start += 1) {
|
|
63
|
+
if (!hasTwoDistinctDigits(start)) {
|
|
64
|
+
repdigits += 1;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const trace = kaprekarTrace(start, 16);
|
|
68
|
+
const steps = trace.length ? trace.length - 1 : 0;
|
|
69
|
+
validStarts += 1;
|
|
70
|
+
if (trace[trace.length - 1] !== 6174) allReach = false;
|
|
71
|
+
if (steps > 7) boundOk = false;
|
|
72
|
+
if (steps < 8) hist[steps] += 1;
|
|
73
|
+
if (steps > maxIterations) {
|
|
74
|
+
maxIterations = steps;
|
|
75
|
+
worstCaseStarts = 1;
|
|
76
|
+
worstTrace = trace.slice();
|
|
77
|
+
} else if (steps === maxIterations) {
|
|
78
|
+
worstCaseStarts += 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const fixedPointOk = kaprekarStep(6174) === 6174;
|
|
83
|
+
const histTotal = hist.reduce((sum, n) => sum + n, 0);
|
|
84
|
+
const histogramOk = histTotal === validStarts;
|
|
85
|
+
const ok = fixedPointOk && allReach && boundOk && histogramOk;
|
|
86
|
+
|
|
87
|
+
const lines = [];
|
|
88
|
+
lines.push('=== Answer ===');
|
|
89
|
+
lines.push('Every valid four-digit start tested reaches 6174, and all of them do so within seven iterations.');
|
|
90
|
+
lines.push('');
|
|
91
|
+
lines.push('=== Reason Why ===');
|
|
92
|
+
lines.push(
|
|
93
|
+
"The program applies Kaprekar's routine to every non-repdigit start, records the iteration count, and keeps witness traces.",
|
|
94
|
+
);
|
|
95
|
+
lines.push(`valid starts checked: ${validStarts}`);
|
|
96
|
+
lines.push(`repdigits excluded : ${repdigits}`);
|
|
97
|
+
lines.push(`max iterations : ${maxIterations}`);
|
|
98
|
+
lines.push(`worst-case starts : ${worstCaseStarts}`);
|
|
99
|
+
lines.push(`worst trace : ${worstTrace.map(fmt4).join(' -> ')}`);
|
|
100
|
+
lines.push(`leading-zero trace : ${leadingTrace.map(fmt4).join(' -> ')}`);
|
|
101
|
+
lines.push('');
|
|
102
|
+
lines.push('=== Check ===');
|
|
103
|
+
lines.push(`6174 fixed point : ${fixedPointOk ? 'yes' : 'no'}`);
|
|
104
|
+
lines.push(`all starts reach it : ${allReach ? 'yes' : 'no'}`);
|
|
105
|
+
lines.push(`bound <= 7 verified : ${boundOk ? 'yes' : 'no'}`);
|
|
106
|
+
lines.push(`histogram total ok : ${histogramOk ? 'yes' : 'no'}`);
|
|
107
|
+
|
|
108
|
+
process.stdout.write(`${lines.join('\n')}\n`);
|
|
109
|
+
process.exit(ok ? 0 : 1);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
main();
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Toy matrix-mechanics example over 2x2 matrices.
|
|
6
|
+
* It highlights spectrum, involution, and a non-zero commutator in a compact exact model.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
function m2(a11, a12, a21, a22) {
|
|
10
|
+
return { a11, a12, a21, a22 };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function mul(a, b) {
|
|
14
|
+
return m2(
|
|
15
|
+
a.a11 * b.a11 + a.a12 * b.a21,
|
|
16
|
+
a.a11 * b.a12 + a.a12 * b.a22,
|
|
17
|
+
a.a21 * b.a11 + a.a22 * b.a21,
|
|
18
|
+
a.a21 * b.a12 + a.a22 * b.a22,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function sub(a, b) {
|
|
23
|
+
return m2(a.a11 - b.a11, a.a12 - b.a12, a.a21 - b.a21, a.a22 - b.a22);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function trace(a) {
|
|
27
|
+
return a.a11 + a.a22;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function det(a) {
|
|
31
|
+
return a.a11 * a.a22 - a.a12 * a.a21;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Evaluate the tiny model exactly, then verify the expected algebraic properties.
|
|
35
|
+
function main() {
|
|
36
|
+
const H = m2(1, 0, 0, 2);
|
|
37
|
+
const X = m2(0, 1, 1, 0);
|
|
38
|
+
const HX = mul(H, X);
|
|
39
|
+
const XH = mul(X, H);
|
|
40
|
+
const C = sub(HX, XH);
|
|
41
|
+
const commutatorNonzero = !!(C.a11 || C.a12 || C.a21 || C.a22);
|
|
42
|
+
const spectrumOk = trace(H) === 3 && det(H) === 2;
|
|
43
|
+
const XX = mul(X, X);
|
|
44
|
+
const involution = XX.a11 === 1 && XX.a12 === 0 && XX.a21 === 0 && XX.a22 === 1;
|
|
45
|
+
const ok = spectrumOk && involution && commutatorNonzero;
|
|
46
|
+
|
|
47
|
+
const lines = [];
|
|
48
|
+
lines.push('=== Answer ===');
|
|
49
|
+
lines.push(
|
|
50
|
+
'In this toy matrix-mechanics model, the Hamiltonian has two discrete energy levels and does not commute with a second observable.',
|
|
51
|
+
);
|
|
52
|
+
lines.push('');
|
|
53
|
+
lines.push('=== Reason Why ===');
|
|
54
|
+
lines.push(`H = [[${H.a11},${H.a12}],[${H.a21},${H.a22}]]`);
|
|
55
|
+
lines.push(`X = [[${X.a11},${X.a12}],[${X.a21},${X.a22}]]`);
|
|
56
|
+
lines.push(`HX = [[${HX.a11},${HX.a12}],[${HX.a21},${HX.a22}]]`);
|
|
57
|
+
lines.push(`XH = [[${XH.a11},${XH.a12}],[${XH.a21},${XH.a22}]]`);
|
|
58
|
+
lines.push(`[H,X] = [[${C.a11},${C.a12}],[${C.a21},${C.a22}]]`);
|
|
59
|
+
lines.push('');
|
|
60
|
+
lines.push('=== Check ===');
|
|
61
|
+
lines.push(`trace/determinant match energy levels: ${spectrumOk ? 'yes' : 'no'}`);
|
|
62
|
+
lines.push(`X^2 = I : ${involution ? 'yes' : 'no'}`);
|
|
63
|
+
lines.push(`[H,X] != 0 : ${commutatorNonzero ? 'yes' : 'no'}`);
|
|
64
|
+
|
|
65
|
+
process.stdout.write(`${lines.join('\n')}\n`);
|
|
66
|
+
process.exit(ok ? 0 : 1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
main();
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Specialized EHDS risk-ranking case with concrete permissions, needs, and scoring rules.
|
|
6
|
+
* Instead of generic policy reasoning, the file evaluates the fixed rule set directly and explains the ranking.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const ACTION = {
|
|
10
|
+
PROVIDE_SECONDARY_USE_DATA: 0,
|
|
11
|
+
DOWNLOAD: 1,
|
|
12
|
+
REMOVE_DIRECT_IDENTIFIERS: 2,
|
|
13
|
+
PROCESS_ONLY_IN_SECURE_ENVIRONMENT: 3,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const CONSTRAINT_KEY = {
|
|
17
|
+
PURPOSE: 0,
|
|
18
|
+
HAS_DATA_PERMIT: 1,
|
|
19
|
+
RESPECT_OPT_OUT_SECONDARY_USE: 2,
|
|
20
|
+
STATISTICALLY_ANONYMISED: 3,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function actionName(a) {
|
|
24
|
+
switch (a) {
|
|
25
|
+
case ACTION.PROVIDE_SECONDARY_USE_DATA:
|
|
26
|
+
return 'provideSecondaryUseData';
|
|
27
|
+
case ACTION.DOWNLOAD:
|
|
28
|
+
return 'download';
|
|
29
|
+
case ACTION.REMOVE_DIRECT_IDENTIFIERS:
|
|
30
|
+
return 'removeDirectIdentifiers';
|
|
31
|
+
case ACTION.PROCESS_ONLY_IN_SECURE_ENVIRONMENT:
|
|
32
|
+
return 'processOnlyInSecureEnvironment';
|
|
33
|
+
default:
|
|
34
|
+
return '?';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const NEEDS = [
|
|
39
|
+
{
|
|
40
|
+
id: 'Need_RequireDataPermit',
|
|
41
|
+
importance: 20,
|
|
42
|
+
description: 'Secondary use should be authorised via an EHDS Data Permit.',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: 'Need_RespectOptOutSecondaryUse',
|
|
46
|
+
importance: 25,
|
|
47
|
+
description: 'Respect the EHDS right to opt out from secondary use.',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 'Need_SecureProcessingEnvironment',
|
|
51
|
+
importance: 18,
|
|
52
|
+
description: 'Secondary-use processing must occur within a secure processing environment.',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'Need_StatisticallyAnonymisedSecondaryUse',
|
|
56
|
+
importance: 15,
|
|
57
|
+
description: 'Secondary use should use statistically anonymised data.',
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
const P1_C = [{ key: CONSTRAINT_KEY.PURPOSE, value: 'HealthcareScientificResearch' }];
|
|
62
|
+
const P2_C = [{ key: CONSTRAINT_KEY.PURPOSE, value: 'TrainTestAndEvaluateHealthAlgorithms' }];
|
|
63
|
+
const P4_D = [{ action: ACTION.REMOVE_DIRECT_IDENTIFIERS }];
|
|
64
|
+
|
|
65
|
+
const PERMISSIONS = [
|
|
66
|
+
{
|
|
67
|
+
id: 'PermSecondaryUseDUA',
|
|
68
|
+
clauseId: 'H1',
|
|
69
|
+
action: ACTION.PROVIDE_SECONDARY_USE_DATA,
|
|
70
|
+
constraints: P1_C,
|
|
71
|
+
duties: [],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: 'PermSecondaryUseAllPatients',
|
|
75
|
+
clauseId: 'H2',
|
|
76
|
+
action: ACTION.PROVIDE_SECONDARY_USE_DATA,
|
|
77
|
+
constraints: P2_C,
|
|
78
|
+
duties: [],
|
|
79
|
+
},
|
|
80
|
+
{ id: 'PermDownloadLocalCopy', clauseId: 'H3', action: ACTION.DOWNLOAD, constraints: [], duties: [] },
|
|
81
|
+
{
|
|
82
|
+
id: 'PermProvidePseudonymisedData',
|
|
83
|
+
clauseId: 'H4',
|
|
84
|
+
action: ACTION.PROVIDE_SECONDARY_USE_DATA,
|
|
85
|
+
constraints: [],
|
|
86
|
+
duties: P4_D,
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
const MISSING = {
|
|
91
|
+
MISSING_DATA_PERMIT: 0,
|
|
92
|
+
MISSING_OPT_OUT: 1,
|
|
93
|
+
MISSING_SECURE_ENV: 2,
|
|
94
|
+
MISSING_STAT_ANON: 3,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Risk rules combine a base severity with the importance of the unmet need.
|
|
98
|
+
const RULES = [
|
|
99
|
+
{
|
|
100
|
+
ruleId: 'R1',
|
|
101
|
+
permissionId: 'PermSecondaryUseDUA',
|
|
102
|
+
clauseId: 'H1',
|
|
103
|
+
needId: 'Need_RequireDataPermit',
|
|
104
|
+
baseScore: 80,
|
|
105
|
+
riskSource: 'Secondary use permitted without EHDS Data Permit.',
|
|
106
|
+
mitigation: 'Require an EHDS Data Permit before secondary use.',
|
|
107
|
+
missing: MISSING.MISSING_DATA_PERMIT,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
ruleId: 'R2',
|
|
111
|
+
permissionId: 'PermSecondaryUseAllPatients',
|
|
112
|
+
clauseId: 'H2',
|
|
113
|
+
needId: 'Need_RespectOptOutSecondaryUse',
|
|
114
|
+
baseScore: 75,
|
|
115
|
+
riskSource: 'Opt-out from secondary use not explicitly respected.',
|
|
116
|
+
mitigation: 'Exclude records of persons who exercised the EHDS opt-out.',
|
|
117
|
+
missing: MISSING.MISSING_OPT_OUT,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
ruleId: 'R3',
|
|
121
|
+
permissionId: 'PermDownloadLocalCopy',
|
|
122
|
+
clauseId: 'H3',
|
|
123
|
+
needId: 'Need_SecureProcessingEnvironment',
|
|
124
|
+
baseScore: 70,
|
|
125
|
+
riskSource: 'Local download permitted; secure processing environment not required.',
|
|
126
|
+
mitigation: 'Require processing only within a secure processing environment.',
|
|
127
|
+
missing: MISSING.MISSING_SECURE_ENV,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
ruleId: 'R4',
|
|
131
|
+
permissionId: 'PermProvidePseudonymisedData',
|
|
132
|
+
clauseId: 'H4',
|
|
133
|
+
needId: 'Need_StatisticallyAnonymisedSecondaryUse',
|
|
134
|
+
baseScore: 65,
|
|
135
|
+
riskSource: 'Statistical anonymisation safeguard missing for secondary use.',
|
|
136
|
+
mitigation: 'Require statistically anonymised data for secondary use.',
|
|
137
|
+
missing: MISSING.MISSING_STAT_ANON,
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
function findNeed(id) {
|
|
142
|
+
return NEEDS.find((need) => need.id === id) || null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function findPerm(id) {
|
|
146
|
+
return PERMISSIONS.find((permission) => permission.id === id) || null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function hasConstraint(permission, key) {
|
|
150
|
+
return permission.constraints.some((constraint) => constraint.key === key);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function hasDuty(permission, action) {
|
|
154
|
+
return permission.duties.some((duty) => duty.action === action);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function missing(permission, kind) {
|
|
158
|
+
switch (kind) {
|
|
159
|
+
case MISSING.MISSING_DATA_PERMIT:
|
|
160
|
+
return !hasConstraint(permission, CONSTRAINT_KEY.HAS_DATA_PERMIT);
|
|
161
|
+
case MISSING.MISSING_OPT_OUT:
|
|
162
|
+
return !hasConstraint(permission, CONSTRAINT_KEY.RESPECT_OPT_OUT_SECONDARY_USE);
|
|
163
|
+
case MISSING.MISSING_SECURE_ENV:
|
|
164
|
+
return !hasDuty(permission, ACTION.PROCESS_ONLY_IN_SECURE_ENVIRONMENT);
|
|
165
|
+
case MISSING.MISSING_STAT_ANON:
|
|
166
|
+
return !hasConstraint(permission, CONSTRAINT_KEY.STATISTICALLY_ANONYMISED);
|
|
167
|
+
default:
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Materialize the ranked risk list and verify the ordering and scores.
|
|
173
|
+
function main() {
|
|
174
|
+
const risks = [];
|
|
175
|
+
for (const rule of RULES) {
|
|
176
|
+
const permission = findPerm(rule.permissionId);
|
|
177
|
+
const need = findNeed(rule.needId);
|
|
178
|
+
if (permission && need && missing(permission, rule.missing)) {
|
|
179
|
+
const raw = rule.baseScore + need.importance;
|
|
180
|
+
const score = raw > 100 ? 100 : raw;
|
|
181
|
+
risks.push({
|
|
182
|
+
clauseId: rule.clauseId,
|
|
183
|
+
permissionId: rule.permissionId,
|
|
184
|
+
needId: rule.needId,
|
|
185
|
+
action: permission.action,
|
|
186
|
+
needImportance: need.importance,
|
|
187
|
+
scoreRaw: raw,
|
|
188
|
+
score,
|
|
189
|
+
riskSource: rule.riskSource,
|
|
190
|
+
mitigation: rule.mitigation,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
risks.sort((a, b) => {
|
|
196
|
+
if (b.score !== a.score) return b.score - a.score;
|
|
197
|
+
return a.clauseId.localeCompare(b.clauseId);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
let scoreFormulaOk = true;
|
|
201
|
+
let sortedOk = true;
|
|
202
|
+
let mitigationsOk = true;
|
|
203
|
+
for (let i = 0; i < risks.length; i += 1) {
|
|
204
|
+
const rule = RULES[i];
|
|
205
|
+
const need = findNeed(rule.needId);
|
|
206
|
+
const expected = Math.min(rule.baseScore + need.importance, 100);
|
|
207
|
+
if (risks.length > 0 && risks[i].score !== expected) scoreFormulaOk = false;
|
|
208
|
+
if (!risks[i].mitigation) mitigationsOk = false;
|
|
209
|
+
if (i + 1 < risks.length && risks[i].score < risks[i + 1].score) sortedOk = false;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const topPairOk =
|
|
213
|
+
risks.length >= 2 &&
|
|
214
|
+
risks[0].clauseId === 'H1' &&
|
|
215
|
+
risks[0].score === 100 &&
|
|
216
|
+
risks[1].clauseId === 'H2' &&
|
|
217
|
+
risks[1].score === 100;
|
|
218
|
+
|
|
219
|
+
const ok = risks.length === 4 && scoreFormulaOk && sortedOk && topPairOk && mitigationsOk;
|
|
220
|
+
|
|
221
|
+
const lines = [];
|
|
222
|
+
lines.push('=== Answer ===');
|
|
223
|
+
lines.push(
|
|
224
|
+
'The EHDS secondary-use agreement yields four ranked risks; H1 and H2 normalize to score 100, followed by H3 at 88 and H4 at 80.',
|
|
225
|
+
);
|
|
226
|
+
lines.push('');
|
|
227
|
+
lines.push('=== Reason Why ===');
|
|
228
|
+
lines.push(
|
|
229
|
+
'The agreement instantiates concrete clauses, permissions, patient needs, and rule applications. A risk appears when a permission is missing a required safeguard.',
|
|
230
|
+
);
|
|
231
|
+
for (let i = 0; i < risks.length; i += 1) {
|
|
232
|
+
const risk = risks[i];
|
|
233
|
+
lines.push(`Risk #${i + 1}`);
|
|
234
|
+
lines.push(` clause : ${risk.clauseId}`);
|
|
235
|
+
lines.push(` permission : ${risk.permissionId}`);
|
|
236
|
+
lines.push(` action : ${actionName(risk.action)}`);
|
|
237
|
+
lines.push(` violated need : ${risk.needId}`);
|
|
238
|
+
lines.push(` score raw : ${risk.scoreRaw}`);
|
|
239
|
+
lines.push(` score : ${risk.score}`);
|
|
240
|
+
lines.push(` source : ${risk.riskSource}`);
|
|
241
|
+
lines.push(` mitigation : ${risk.mitigation}`);
|
|
242
|
+
}
|
|
243
|
+
lines.push('');
|
|
244
|
+
lines.push('=== Check ===');
|
|
245
|
+
lines.push(`risk count = 4 : ${risks.length === 4 ? 'yes' : 'no'}`);
|
|
246
|
+
lines.push(`score formula recomputes: ${scoreFormulaOk ? 'yes' : 'no'}`);
|
|
247
|
+
lines.push(`ranking sorted desc : ${sortedOk ? 'yes' : 'no'}`);
|
|
248
|
+
lines.push(`expected top pair : ${topPairOk ? 'yes' : 'no'}`);
|
|
249
|
+
lines.push(`every risk has mitigation: ${mitigationsOk ? 'yes' : 'no'}`);
|
|
250
|
+
|
|
251
|
+
process.stdout.write(`${lines.join('\n')}\n`);
|
|
252
|
+
process.exit(ok ? 0 : 1);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
main();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
=== Answer ===
|
|
2
|
+
For starts 1..=10000, every tested value reaches 1 under the Collatz map.
|
|
3
|
+
|
|
4
|
+
=== Reason Why ===
|
|
5
|
+
The program applies the standard Collatz rule, memoizes stopping times, and tracks the hardest witnesses.
|
|
6
|
+
starts checked : 10000
|
|
7
|
+
max steps : 261
|
|
8
|
+
max-steps start : 6171
|
|
9
|
+
highest peak : 27114424
|
|
10
|
+
peak start : 9663
|
|
11
|
+
trace(27) steps : 111
|
|
12
|
+
trace(27) peak : 9232
|
|
13
|
+
|
|
14
|
+
=== Check ===
|
|
15
|
+
all reach 1 : yes
|
|
16
|
+
trace(27) valid : yes
|
|
17
|
+
max-steps witness ok: yes
|
|
18
|
+
peak witness ok : yes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
=== Answer ===
|
|
2
|
+
The control query is satisfied: the source facts derive concrete outputs for actuator1 and actuator2.
|
|
3
|
+
|
|
4
|
+
=== Reason Why ===
|
|
5
|
+
The helper rule measurement10(input1) is derived first, then both control rules are evaluated from the available facts.
|
|
6
|
+
measurement10(input1): 2.236068
|
|
7
|
+
actuator1 : 39.273462
|
|
8
|
+
actuator2 : 26.080000
|
|
9
|
+
|
|
10
|
+
=== Check ===
|
|
11
|
+
query satisfied : yes
|
|
12
|
+
unique actuators : yes
|
|
13
|
+
actuator1 formula ok : yes
|
|
14
|
+
actuator2 formula ok : yes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
=== Answer ===
|
|
2
|
+
The deep taxonomy chain reaches the goal from the seed fact after deriving the full class ladder up to N(100000).
|
|
3
|
+
|
|
4
|
+
=== Reason Why ===
|
|
5
|
+
Starting from Ind:N(0), each N(i) derives N(i+1), I(i+1), and J(i+1); N(100000) then derives A2 and the goal.
|
|
6
|
+
seed facts : 1
|
|
7
|
+
rules : 100002
|
|
8
|
+
derived facts : 300003
|
|
9
|
+
type facts : 300002
|
|
10
|
+
|
|
11
|
+
=== Check ===
|
|
12
|
+
goal reached : yes
|
|
13
|
+
N(100000) seen: yes
|
|
14
|
+
A2 derived : yes
|
|
15
|
+
count formula : yes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
=== Answer ===
|
|
2
|
+
The scanner is allowed to use a neutral shopping insight and recommends Low-Sugar Tea Biscuits instead of Classic Tea Biscuits.
|
|
3
|
+
|
|
4
|
+
=== Reason Why ===
|
|
5
|
+
The phone desensitizes a diabetes-related household condition into a scoped low-sugar need, wraps it in an expiring Insight+Policy envelope, and signs it.
|
|
6
|
+
scanned product : Classic Tea Biscuits
|
|
7
|
+
suggested alternative: Low-Sugar Tea Biscuits
|
|
8
|
+
payload SHA-256 : e1ad69852c98ca7697a164dbc6f0ca28f873508a6676865dba37b81faa66ebcb
|
|
9
|
+
HMAC-SHA256 : 518a84185e2975928c6c935dae6e251a071766078c6e9e70d6f583a1147728db
|
|
10
|
+
|
|
11
|
+
=== Check ===
|
|
12
|
+
signature verifies : yes
|
|
13
|
+
payload hash matches : yes
|
|
14
|
+
minimization strips sensitive terms: yes
|
|
15
|
+
scope complete : yes
|
|
16
|
+
authorization allowed : yes
|
|
17
|
+
high-sugar banner : yes
|
|
18
|
+
alternative lowers sugar : yes
|
|
19
|
+
duty timing consistent : yes
|
|
20
|
+
marketing prohibited : yes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
=== Answer ===
|
|
2
|
+
Euler's identity holds exactly in this exact-arithmetic model: exp(i*pi) + 1 = 0.
|
|
3
|
+
|
|
4
|
+
=== Reason Why ===
|
|
5
|
+
exp(i*pi) is represented as (-1, 0) and adding (1, 0) gives the exact zero complex number.
|
|
6
|
+
exp(i*pi) : (-1, 0)
|
|
7
|
+
exp(i*pi)+1 : (0, 0)
|
|
8
|
+
|exp(i*pi)|^2: 1
|
|
9
|
+
|
|
10
|
+
=== Check ===
|
|
11
|
+
identity exact: yes
|
|
12
|
+
unit circle : yes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
=== Answer ===
|
|
2
|
+
The requested Fibonacci values are computed exactly, up to F(10000).
|
|
3
|
+
|
|
4
|
+
=== Reason Why ===
|
|
5
|
+
The main computation uses the defining recurrence F(n+1)=F(n)+F(n-1), and the results are cross-checked with fast doubling.
|
|
6
|
+
value[0] : F(0) = 0
|
|
7
|
+
value[1] : F(1) = 1
|
|
8
|
+
value[2] : F(10) = 55
|
|
9
|
+
value[3] : F(100) = 354224848179261915075
|
|
10
|
+
value[4] : F(1000) = 43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875
|
|
11
|
+
value[5] : F(10000) = 33644764876431783266621612005107543310302148460680063906564769974680081442166662368155595513633734025582065332680836159373734790483865268263040892463056431887354544369559827491606602099884183933864652731300088830269235673613135117579297437854413752130520504347701602264758318906527890855154366159582987279682987510631200575428783453215515103870818298969791613127856265033195487140214287532698187962046936097879900350962302291026368131493195275630227837628441540360584402572114334961180023091208287046088923962328835461505776583271252546093591128203925285393434620904245248929403901706233888991085841065183173360437470737908552631764325733993712871937587746897479926305837065742830161637408969178426378624212835258112820516370298089332099905707920064367426202389783111470054074998459250360633560933883831923386783056136435351892133279732908133732642652633989763922723407882928177953580570993691049175470808931841056146322338217465637321248226383092103297701648054726243842374862411453093812206564914032751086643394517512161526545361333111314042436854805106765843493523836959653428071768775328348234345557366719731392746273629108210679280784718035329131176778924659089938635459327894523777674406192240337638674004021330343297496902028328145933418826817683893072003634795623117103101291953169794607632737589253530772552375943788434504067715555779056450443016640119462580972216729758615026968443146952034614932291105970676243268515992834709891284706740862008587135016260312071903172086094081298321581077282076353186624611278245537208532365305775956430072517744315051539600905168603220349163222640885248852433158051534849622434848299380905070483482449327453732624567755879089187190803662058009594743150052402532709746995318770724376825907419939632265984147498193609285223945039707165443156421328157688908058783183404917434556270520223564846495196112460268313970975069382648706613264507665074611512677522748621598642530711298441182622661057163515069260029861704945425047491378115154139941550671256271197133252763631939606902895650288268608362241082050562430701794976171121233066073310059947366875
|
|
12
|
+
digits in F(1000) : 209
|
|
13
|
+
digits in F(10000) : 2090
|
|
14
|
+
|
|
15
|
+
=== Check ===
|
|
16
|
+
F(10) = 55 : yes
|
|
17
|
+
fast doubling agrees : yes
|
|
18
|
+
Cassini at n=100 : yes
|
|
19
|
+
F(1000) has 209 digits: yes
|
|
20
|
+
F(10000) has 2090 digits: yes
|
|
21
|
+
F(10000) ends in 875 : yes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
=== Answer ===
|
|
2
|
+
Every even integer from 4 through 1000 has at least one Goldbach decomposition in the tested range.
|
|
3
|
+
|
|
4
|
+
=== Reason Why ===
|
|
5
|
+
The program builds a prime table, enumerates unordered pairs p+q=n for each even target, and summarizes sparse and rich cases.
|
|
6
|
+
even targets checked : 499
|
|
7
|
+
total decompositions : 8222
|
|
8
|
+
fewest decompositions: 1
|
|
9
|
+
hardest targets : 4, 6, 8, 12
|
|
10
|
+
most decompositions : 52
|
|
11
|
+
richest target : 990
|
|
12
|
+
balanced pair(1000) : 491 + 509
|
|
13
|
+
|
|
14
|
+
=== Check ===
|
|
15
|
+
all represented : yes
|
|
16
|
+
prime count known : yes
|
|
17
|
+
balanced pair valid : yes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
=== Answer ===
|
|
2
|
+
The GPS case finds all goal routes from Gent to Oostende that satisfy the route constraints.
|
|
3
|
+
case : gps
|
|
4
|
+
routes : 2
|
|
5
|
+
|
|
6
|
+
=== Reason Why ===
|
|
7
|
+
Routes are built compositionally from direct descriptions, with duration and cost added and belief and comfort combined multiplicatively.
|
|
8
|
+
Route #1
|
|
9
|
+
Steps : 2
|
|
10
|
+
Duration : 2400 s (≤ 5000)
|
|
11
|
+
Cost : 0.010 (≤ 5.0)
|
|
12
|
+
Belief : 0.941 (≥ 0.2)
|
|
13
|
+
Comfort : 0.990 (≥ 0.4)
|
|
14
|
+
Stages : 1 (≤ 1)
|
|
15
|
+
1. drive_gent_brugge
|
|
16
|
+
2. drive_brugge_oostende
|
|
17
|
+
|
|
18
|
+
Route #2
|
|
19
|
+
Steps : 3
|
|
20
|
+
Duration : 4100 s (≤ 5000)
|
|
21
|
+
Cost : 0.018 (≤ 5.0)
|
|
22
|
+
Belief : 0.903 (≥ 0.2)
|
|
23
|
+
Comfort : 0.980 (≥ 0.4)
|
|
24
|
+
Stages : 1 (≤ 1)
|
|
25
|
+
1. drive_gent_kortrijk
|
|
26
|
+
2. drive_kortrijk_brugge
|
|
27
|
+
3. drive_brugge_oostende
|
|
28
|
+
|
|
29
|
+
=== Check ===
|
|
30
|
+
all routes satisfy constraints : yes
|
|
31
|
+
all routes hit goal endpoints : yes
|
|
32
|
+
metrics recompute from steps : yes
|
|
33
|
+
expected route count (= 2) : yes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
=== Answer ===
|
|
2
|
+
Every valid four-digit start tested reaches 6174, and all of them do so within seven iterations.
|
|
3
|
+
|
|
4
|
+
=== Reason Why ===
|
|
5
|
+
The program applies Kaprekar's routine to every non-repdigit start, records the iteration count, and keeps witness traces.
|
|
6
|
+
valid starts checked: 9990
|
|
7
|
+
repdigits excluded : 10
|
|
8
|
+
max iterations : 7
|
|
9
|
+
worst-case starts : 2184
|
|
10
|
+
worst trace : 0014 -> 4086 -> 8172 -> 7443 -> 3996 -> 6264 -> 4176 -> 6174
|
|
11
|
+
leading-zero trace : 2111 -> 0999 -> 8991 -> 8082 -> 8532 -> 6174
|
|
12
|
+
|
|
13
|
+
=== Check ===
|
|
14
|
+
6174 fixed point : yes
|
|
15
|
+
all starts reach it : yes
|
|
16
|
+
bound <= 7 verified : yes
|
|
17
|
+
histogram total ok : yes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
=== Answer ===
|
|
2
|
+
In this toy matrix-mechanics model, the Hamiltonian has two discrete energy levels and does not commute with a second observable.
|
|
3
|
+
|
|
4
|
+
=== Reason Why ===
|
|
5
|
+
H = [[1,0],[0,2]]
|
|
6
|
+
X = [[0,1],[1,0]]
|
|
7
|
+
HX = [[0,1],[2,0]]
|
|
8
|
+
XH = [[0,2],[1,0]]
|
|
9
|
+
[H,X] = [[0,-1],[1,0]]
|
|
10
|
+
|
|
11
|
+
=== Check ===
|
|
12
|
+
trace/determinant match energy levels: yes
|
|
13
|
+
X^2 = I : yes
|
|
14
|
+
[H,X] != 0 : yes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
=== Answer ===
|
|
2
|
+
The EHDS secondary-use agreement yields four ranked risks; H1 and H2 normalize to score 100, followed by H3 at 88 and H4 at 80.
|
|
3
|
+
|
|
4
|
+
=== Reason Why ===
|
|
5
|
+
The agreement instantiates concrete clauses, permissions, patient needs, and rule applications. A risk appears when a permission is missing a required safeguard.
|
|
6
|
+
Risk #1
|
|
7
|
+
clause : H1
|
|
8
|
+
permission : PermSecondaryUseDUA
|
|
9
|
+
action : provideSecondaryUseData
|
|
10
|
+
violated need : Need_RequireDataPermit
|
|
11
|
+
score raw : 100
|
|
12
|
+
score : 100
|
|
13
|
+
source : Secondary use permitted without EHDS Data Permit.
|
|
14
|
+
mitigation : Require an EHDS Data Permit before secondary use.
|
|
15
|
+
Risk #2
|
|
16
|
+
clause : H2
|
|
17
|
+
permission : PermSecondaryUseAllPatients
|
|
18
|
+
action : provideSecondaryUseData
|
|
19
|
+
violated need : Need_RespectOptOutSecondaryUse
|
|
20
|
+
score raw : 100
|
|
21
|
+
score : 100
|
|
22
|
+
source : Opt-out from secondary use not explicitly respected.
|
|
23
|
+
mitigation : Exclude records of persons who exercised the EHDS opt-out.
|
|
24
|
+
Risk #3
|
|
25
|
+
clause : H3
|
|
26
|
+
permission : PermDownloadLocalCopy
|
|
27
|
+
action : download
|
|
28
|
+
violated need : Need_SecureProcessingEnvironment
|
|
29
|
+
score raw : 88
|
|
30
|
+
score : 88
|
|
31
|
+
source : Local download permitted; secure processing environment not required.
|
|
32
|
+
mitigation : Require processing only within a secure processing environment.
|
|
33
|
+
Risk #4
|
|
34
|
+
clause : H4
|
|
35
|
+
permission : PermProvidePseudonymisedData
|
|
36
|
+
action : provideSecondaryUseData
|
|
37
|
+
violated need : Need_StatisticallyAnonymisedSecondaryUse
|
|
38
|
+
score raw : 80
|
|
39
|
+
score : 80
|
|
40
|
+
source : Statistical anonymisation safeguard missing for secondary use.
|
|
41
|
+
mitigation : Require statistically anonymised data for secondary use.
|
|
42
|
+
|
|
43
|
+
=== Check ===
|
|
44
|
+
risk count = 4 : yes
|
|
45
|
+
score formula recomputes: yes
|
|
46
|
+
ranking sorted desc : yes
|
|
47
|
+
expected top pair : yes
|
|
48
|
+
every risk has mitigation: yes
|