Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 19s
Two running sums modulo 65521:
a = (1 + sum of bytes) mod 65521
b = sum of running 'a' values mod 65521
checksum = b * 65536 + a
let adler32 s =
let a = ref 1 in
let b = ref 0 in
let m = 65521 in
for i = 0 to String.length s - 1 do
a := (!a + Char.code s.[i]) mod m;
b := (!b + !a) mod m
done;
!b * 65536 + !a
For 'Wikipedia': 0x11E60398 = 300286872 (the canonical test value).
Tests for-loop accumulating two refs together, modular arithmetic,
and Char.code on s.[i].
96 baseline programs total.
14 lines
226 B
OCaml
14 lines
226 B
OCaml
let adler32 s =
|
|
let a = ref 1 in
|
|
let b = ref 0 in
|
|
let m = 65521 in
|
|
for i = 0 to String.length s - 1 do
|
|
a := (!a + Char.code s.[i]) mod m;
|
|
b := (!b + !a) mod m
|
|
done;
|
|
!b * 65536 + !a
|
|
|
|
;;
|
|
|
|
adler32 "Wikipedia"
|