Skip to content

Commit

Permalink
Attempt to fix wasm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 23, 2024
1 parent 5b0b279 commit 54dca53
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 4 additions & 3 deletions c/src/p0008.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
}
Expand Down
7 changes: 5 additions & 2 deletions docs/_static/test-c.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions docs/_static/test-cp.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 54dca53

Please sign in to comment.