import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; const primes = [2n, 3n, 5n, 7n, 11n, 13n, 17n, 19n, 23n, 29n, 31n, 37n, 41n, 43n]; const known = { 41: ['3784200788231', '300466062738431'], 43: ['830330079152051', '1403312099425139', '11679449232244271', '12252431252517359'], }; const reportedCounts = { 41: 4, 43: 8 }; const args = process.argv.slice(2); assert.equal(args.length, 3, 'Pass the 41# and 43# SAT result files and the published certificate target'); const paths = args.slice(0, 2); const results = []; for (const file of paths) { const input = JSON.parse(readFileSync(file, 'utf8')); assert(input.prime === 41 || input.prime === 43); const ps = primes.filter(p => p <= BigInt(input.prime)); const modulus = ps.reduce((a, p) => a * p, 1n); const gap = BigInt(input.gap); assert.equal(String(modulus), input.modulus); const isSlot = (n, divisors) => divisors.every(p => n % p !== 0n && (n + 2n) % p !== 0n); const starts = new Set([...known[input.prime], ...input.positions.map(row => row.start)]); for (const start of [...starts]) starts.add(String((modulus - BigInt(start) - gap - 2n) % modulus)); const rows = [...starts].map(BigInt).sort((a, b) => a < b ? -1 : a > b ? 1 : 0).map(start => { assert(start >= 0n && start < modulus); assert(isSlot(start, ps)); assert(isSlot(start + gap, ps)); for (let n = start + 1n; n < start + gap; n++) assert(!isSlot(n, ps)); const ancestors = []; for (let n = start; n <= start + gap; n++) { if (isSlot(n, ps.slice(0, -1))) ancestors.push(n); } const ancestry = ancestors.slice(1).map((n, i) => Number(n - ancestors[i])); const interior = ancestry.slice(1, -1).reduce((a, n) => a + n, 0); const submitted = input.positions.find(row => row.start === String(start)); if (submitted) { assert.deepEqual(ancestry, submitted.ancestry); assert.equal(interior, submitted.interior); } return { start: String(start), partner: String((modulus - start - gap - 2n) % modulus), ancestry, interior, newPosition: !known[input.prime].includes(String(start)), }; }); for (const row of rows) { const partner = rows.find(other => other.start === row.partner); assert(partner); assert.deepEqual(row.ancestry, [...partner.ancestry].reverse()); } assert.equal(rows.length, reportedCounts[input.prime]); const classes = [...new Set(rows.map(row => row.interior))].sort((a, b) => a - b).map(interior => ({ interior, gap: input.gap, count: rows.filter(row => row.interior === interior).length, })); results.push({ prime: input.prime, gap: input.gap, certifiedPositions: rows.length, newPositions: rows.filter(row => row.newPosition).length, completeness: `Conditional on the published count ${reportedCounts[input.prime]}; SAT status was ${input.status}`, classes, rows, }); } results.sort((a, b) => a.prime - b.prime); assert.deepEqual(results.map(row => row.prime), [41, 43]); const result = { scope: 'Direct trial-division certificates, not a new global maximum proof or SAT exhaustion claim', results, }; assert.deepEqual(result, JSON.parse(readFileSync(args[2], 'utf8'))); console.log(JSON.stringify(result, null, 2));