Re: Using std.algorithm.iteration to Calculate Hamming Distance

2019-06-23 Thread Samir via Digitalmars-d-learn
On Sunday, 23 June 2019 at 13:29:25 UTC, KnightMare wrote: zip( "hello world", "Hello World" ).map!"a[0] != a[1]".sum Excellent! Thank you!

Re: Using std.algorithm.iteration to Calculate Hamming Distance

2019-06-23 Thread KnightMare via Digitalmars-d-learn
On Sunday, 23 June 2019 at 13:10:51 UTC, Samir wrote: D already has a function to calculate the Levenshtein distance[1]. I am trying to come up with a function to calculate the Hamming distance[2] between two strings, `a` and `b`. So far, this seems to work: foreach (i, j; zip(a, b)) {

Using std.algorithm.iteration to Calculate Hamming Distance

2019-06-23 Thread Samir via Digitalmars-d-learn
D already has a function to calculate the Levenshtein distance[1]. I am trying to come up with a function to calculate the Hamming distance[2] 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