ocaml: phase 5.1 anagram_check.ml baseline (char-frequency array, 2/4 anagrams)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
to_counts builds a 256-slot int array of character frequencies:
let to_counts s =
let counts = Array.make 256 0 in
for i = 0 to String.length s - 1 do
let c = Char.code s.[i] in
counts.(c) <- counts.(c) + 1
done;
counts
same_counts compares two arrays element-by-element via for loop +
bool ref. is_anagram composes them.
Four pairs:
listen ~ silent true
hello !~ world false
anagram ~ nagaram true
abc !~ abcd false (length differs)
sum 2
Exercises Array.make + arr.(i) + arr.(i) <- v + nested for loops +
Char.code + s.[i].
57 baseline programs total.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"ackermann.ml": 125,
|
||||
"anagram_check.ml": 2,
|
||||
"anagrams.ml": 3,
|
||||
"bag.ml": 3,
|
||||
"bigint_add.ml": 28,
|
||||
|
||||
Reference in New Issue
Block a user