From 54dca5371ca6cad7c3c0432c06b3bff0c11b2f67 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Thu, 22 Aug 2024 22:42:37 -0500 Subject: [PATCH] Attempt to fix wasm issues --- c/src/p0008.c | 7 ++++--- docs/_static/test-c.html | 7 +++++-- docs/_static/test-cp.html | 7 +++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/c/src/p0008.c b/c/src/p0008.c index 7acb13cc..c0aad1fa 100644 --- a/c/src/p0008.c +++ b/c/src/p0008.c @@ -39,7 +39,8 @@ Find the thirteen adjacent digits in the 1000-digit number that have the greates uint64_t EMSCRIPTEN_KEEPALIVE p0008() { size_t i, j; - uint64_t answer = 0, tmp; + uint64_t answer = 0; + uintmax_t tmp; // possibly necessary for wasm to work well const char *plain_digits = ("73167176531330624919225119674426574742355349194934" "96983520312774506326239578318016984801869478851843" "85861560789112949495459501737958331952853208805511" @@ -62,12 +63,12 @@ uint64_t EMSCRIPTEN_KEEPALIVE p0008() { "71636269561882670428252483600823257530420752963450"); char digits[1000]; for (i = 0; i < 1000; i++) - digits[i] = plain_digits[i] - 0x30; + digits[i] = plain_digits[i] - '0'; for (i = 0; i < 1000 - 13; i++) { tmp = digits[i]; for (j = i + 1; j < i + 13; j++) tmp *= digits[j]; - answer = max(answer, tmp); + answer = max(answer, (uint64_t) tmp); } return answer; } diff --git a/docs/_static/test-c.html b/docs/_static/test-c.html index 3214b101..ad951e23 100644 --- a/docs/_static/test-c.html +++ b/docs/_static/test-c.html @@ -22,10 +22,13 @@ const formattedQuestion = `${p}`.padStart(4, '0'); const func = wasm[`_p${formattedQuestion}`]; if (func === undefined) continue; - const expected = Number(get_js_answer(p)); + let expected = get_js_answer(p); + if (typeof expected === 'bigint') { + expected = Number(expected); + } describe(`run test ${p}`, function() { this.timeout(Infinity); - it(`should return ${expected}`, async () => { + it(`should return ${expected}`, () => { const answer = func(); console.log(p, answer, expected); if (answer !== expected) { diff --git a/docs/_static/test-cp.html b/docs/_static/test-cp.html index ce66d87d..400d8331 100644 --- a/docs/_static/test-cp.html +++ b/docs/_static/test-cp.html @@ -21,10 +21,13 @@ const formattedQuestion = `${p}`.padStart(4, '0'); const func = wasm[`_p${formattedQuestion}`]; if (func === undefined) continue; - const expected = Number(get_js_answer(p)); + let expected = get_js_answer(p); + if (typeof expected === 'bigint') { + expected = Number(expected); + } describe(`run test ${p}`, function() { this.timeout(Infinity); - it(`should return ${expected}`, async () => { + it(`should return ${expected}`, () => { const answer = func(); console.log(p, answer, expected); if (answer !== expected) {