ocaml: phase 5.1 hamming.ml baseline (Hamming distance, 3+2-1 = 4)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Counts position-wise differences between two strings of equal
length; returns -1 sentinel for length mismatch:
let hamming s t =
if String.length s <> String.length t then -1
else
let d = ref 0 in
for i = 0 to String.length s - 1 do
if s.[i] <> t.[i] then d := !d + 1
done;
!d
Three test cases:
'karolin' vs 'kathrin' 3 (positions 2,3,4)
'1011101' vs '1001001' 2 (positions 2,4)
'abc' vs 'abcd' -1 (length mismatch)
sum 4
91 baseline programs total.
This commit is contained in:
@@ -407,6 +407,13 @@ _Newest first._
|
||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||
recursive match, List.append, List.fold_left.
|
||||
- 2026-05-09 Phase 5.1 — hamming.ml baseline (Hamming distance,
|
||||
3 + 2 + (-1) = 4). Counts position-wise differences in equal-length
|
||||
strings; returns -1 sentinel for length mismatch.
|
||||
karolin vs kathrin 3 (positions 2,3,4)
|
||||
1011101 vs 1001001 2 (positions 2,4)
|
||||
abc vs abcd -1 (length mismatch)
|
||||
Sum = 4. 91 baseline programs total.
|
||||
- 2026-05-09 Phase 5.1 — xor_cipher.ml baseline (XOR roll-key
|
||||
encryption, round-trip → 601). For each character, XOR with the
|
||||
corresponding key char (key cycled via `i mod kn`). Encrypts
|
||||
|
||||
Reference in New Issue
Block a user