Created
September 20, 2023 22:40
-
-
Save jarble/62ab089629ddb2587b0cd14d2baabaac to your computer and use it in GitHub Desktop.
Hamming distance in MiniZinc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function int: hamming_distance(array[int] of int: arr1, array[int] of int: arr2) = | |
sum([if arr1[i] != arr2[i] then 1 else 0 endif | i in index_set(arr1)]); | |
% Example usage | |
array[int] of int: arr1 = [107, 97, 114, 111, 108, 105, 110]; | |
array[int] of int: arr2 = [107, 97, 116, 104, 114, 105, 110]; | |
int: distance = hamming_distance(arr1, arr2); | |
output ["The Hamming distance is ", show(distance)]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment