MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

use patched mir

+51 -36
+50
examples/demo/triples.js
··· 1 + const tripleCache = new Map(); 2 + const gcdCache = new Map(); 3 + 4 + function gcd(a, b) { 5 + const key = (a << 16) | b; 6 + if (gcdCache.has(key)) return gcdCache.get(key); 7 + const result = b === 0 ? a : gcd(b, a % b); 8 + gcdCache.set(key, result); 9 + return result; 10 + } 11 + 12 + function pushMultiples(a, b, c, k, limit, acc) { 13 + if (k * c > limit) return acc; 14 + acc.push([k * a, k * b, k * c]); 15 + return pushMultiples(a, b, c, k + 1, limit, acc); 16 + } 17 + 18 + function generate(m, n, limit, acc) { 19 + if (m * m + 1 > limit) return acc; 20 + if (n >= m) return generate(m + 1, 1, limit, acc); 21 + 22 + const c = m * m + n * n; 23 + if (c > limit) return generate(m + 1, 1, limit, acc); 24 + 25 + if (((m ^ n) & 1) === 1 && gcd(m, n) === 1) { 26 + const p = m * m - n * n; 27 + const q = 2 * m * n; 28 + const [a, b] = p < q ? [p, q] : [q, p]; 29 + pushMultiples(a, b, c, 1, limit, acc); 30 + } 31 + 32 + return generate(m, n + 1, limit, acc); 33 + } 34 + 35 + function pythagoreanTriples(limit) { 36 + if (tripleCache.has(limit)) return tripleCache.get(limit); 37 + const triples = generate(2, 1, limit, []); 38 + triples.sort((x, y) => x[2] - y[2] || x[0] - y[0]); 39 + tripleCache.set(limit, triples); 40 + return triples; 41 + } 42 + 43 + const start = performance.now(); 44 + const result = pythagoreanTriples(200); 45 + const end = performance.now(); 46 + 47 + console.log(`Found ${result.length} Pythagorean triples with c โ‰ค 200`); 48 + console.log(result); 49 + 50 + console.log(`Time: ${(end - start).toFixed(4)} ms (${((end - start) * 1000).toFixed(2)} ยตs)`);
+1 -2
vendor/mir.wrap
··· 1 1 [wrap-git] 2 - url = https://github.com/vnmakarov/mir.git 2 + url = https://github.com/themackabu/mir.git 3 3 revision = head 4 - patch_directory = mir 5 4 depth = 1 6 5 7 6 [provide]
-34
vendor/packagefiles/mir/meson.build
··· 1 - project('mir', 'c') 2 - 3 - cc = meson.get_compiler('c') 4 - cpu = host_machine.cpu_family() 5 - 6 - # mir-gen-<arch>.c files are #include'd directly inside mir-gen.c โ€” they are 7 - # NOT standalone compilation units and must not be listed as sources here. 8 - mir_sources = files('mir.c', 'mir-gen.c') 9 - 10 - mir_warn_args = cc.get_supported_arguments([ 11 - '-Wno-unused-function', 12 - '-Wno-unused-variable', 13 - '-Wno-unused-parameter', 14 - '-Wno-sign-compare', 15 - '-Wno-missing-field-initializers', 16 - '-Wno-implicit-fallthrough', 17 - '-Wno-pedantic', 18 - '-Wno-format-nonliteral', 19 - '-Wno-cast-function-type', 20 - '-Wno-double-promotion', 21 - '-Wno-conversion', 22 - ]) 23 - 24 - mir_lib = static_library( 25 - 'mir', 26 - mir_sources, 27 - c_args: mir_warn_args, 28 - install: false, 29 - ) 30 - 31 - mir_dep = declare_dependency( 32 - link_with: mir_lib, 33 - include_directories: include_directories('.'), 34 - )