Files
alexm 568474d52f
Test (in pplus-core) / in-core (push) Failing after 28m44s
Initial commit
2026-11-12 22:23:48 -05:00

16 lines
583 B
Plaintext

// HammingDistance: how many positions of two sequences of the same length
// hold different letters. The INVARIANT is what makes the ENSURE provable:
// after I positions, at most I mismatches can have been counted.
FUNCTION HammingDistance(S : STRING, T : STRING) RETURNS INTEGER
REQUIRE LENGTH(S) == LENGTH(T)
ENSURE 0 <= RESULT AND RESULT <= LENGTH(S)
DECLARE Count : INTEGER <- 0
FOR I <- 0 TO LENGTH(S)
INVARIANT 0 <= Count AND Count <= I
IF S[I] != T[I] THEN
Count <- Count + 1
ENDIF
NEXT I
RETURN Count
ENDFUNCTION