MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / bruteForce

Function bruteForce

test/compute-engine/solve-diophantine.test.ts:30–43  ·  view source on GitHub ↗

Brute-force the integer solutions of a two-unknown equation over a box, as a * lexicographically sorted array — the oracle the symbolic path must match.

(
  f: (x: number, y: number) => number,
  xlo: number,
  xhi: number,
  ylo: number,
  yhi: number
)

Source from the content-addressed store, hash-verified

28/** Brute-force the integer solutions of a two-unknown equation over a box, as a
29 * lexicographically sorted array — the oracle the symbolic path must match. */
30function bruteForce(
31 f: (x: number, y: number) => number,
32 xlo: number,
33 xhi: number,
34 ylo: number,
35 yhi: number
36): number[][] {
37 const out: number[][] = [];
38 for (let x = xlo; x <= xhi; x++)
39 for (let y = ylo; y <= yhi; y++)
40 if (f(x, y) === 0) out.push([x, y]);
41 out.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
42 return out;
43}
44
45describe('DIOPHANTINE — linear, bounded domains', () => {
46 test('3x + 4y = 7 over [-10,10]² yields the exact lattice line', () => {

Callers 1

Calls 1

fFunction · 0.70

Tested by

no test coverage detected