gmp_hamdist

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

gmp_hamdistDistanza dell'hamming

Descrizione

gmp_hamdist(resource $a, resource $b): int

Restituisce la distanza di hamming tra a e b. Entrambe gli operandi dovrebbero essere non-negativi.

add a note add a note

User Contributed Notes 2 notes

up
3
Bas Vijfwinkel
4 years ago
For those without gmp support :

$hamming_distance = count(array_diff_assoc(str_split($string1), str_split($string2)));

And if you are not sure if your strings have equal length :

$hamming_distance = count(array_diff_assoc(str_split(str_pad($string1,strlen($string2)-strlen($string1),' ')), str_split(str_pad($string2,strlen($string1)-strlen($string2),' '))));
up
0
grabzila at gmail dot com
1 year ago
<?php
$hamdist
= gmp_hamdist(-100, -10); // 4
$hamdist = gmp_hamdist(100, 10);  // 5
?>

The function works great with negative numbers.
To Top