## digitalmars.D.learn - Using std.algorithm.iteration to Calculate Hamming Distance

• Samir (14/14) Jun 23 2019 D already has a function to calculate the Levenshtein
• KnightMare (2/10) Jun 23 2019 zip( "hello world", "Hello World" ).map!"a != a".sum
• Samir (2/3) Jun 23 2019 Excellent! Thank you!
```D already has a function to calculate the Levenshtein
distance.  I am trying to come up with a function to calculate
the Hamming distance between two strings, `a` and `b`.  So
far, this seems to work:

foreach (i, j; zip(a, b)) {
if (i != j)
++hammingDistance;
}

Is there a way to use any of the std.algorithm.iteration
algorithms such as `filter` or `map` to do this as well?


https://dlang.org/phobos/std_algorithm_comparison.html#levenshteinDistance
 https://en.wikipedia.org/wiki/Hamming_distance
 https://dlang.org/phobos/std_algorithm_iteration.html
```
Jun 23 2019
```On Sunday, 23 June 2019 at 13:10:51 UTC, Samir wrote:
D already has a function to calculate the Levenshtein
distance.  I am trying to come up with a function to
calculate the Hamming distance between two strings, `a` and
`b`.  So far, this seems to work:

foreach (i, j; zip(a, b)) {
if (i != j)
++hammingDistance;
}

zip( "hello world", "Hello World" ).map!"a != a".sum
```
Jun 23 2019
```On Sunday, 23 June 2019 at 13:29:25 UTC, KnightMare wrote:
zip( "hello world", "Hello World" ).map!"a != a".sum

Excellent!  Thank you!
```
Jun 23 2019