Sha256: 0f9ea603ff6e794125f0d1ddf0a792cf8ca283a79227978ae29b7372730fc35d

Contents?: true

Size: 528 Bytes

Versions: 396

Compression:

Stored size: 528 Bytes

Contents

#include "hamming.h"
#include <algorithm>
#include <stdexcept>

namespace hamming
{

int compute(std::string const& lhs, std::string const& rhs)
{
    if (rhs.length() != lhs.length())
    {
        throw std::domain_error("Hamming distance is not defined for different length strings.");
    }

    int count = 0;
    for (auto p = std::mismatch(lhs.begin(), lhs.end(), rhs.begin());
        p.first != lhs.end();
        p = std::mismatch(++p.first, lhs.end(), ++p.second))
    {
        ++count;
    }
    return count;
}

}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.179 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.178 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.177 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.176 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.175 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.174 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.173 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.172 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.171 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.170 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.169 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.167 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.166 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.165 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.164 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.163 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.162 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.161 tracks/cpp/exercises/hamming/example.cpp
trackler-2.2.1.160 tracks/cpp/exercises/hamming/example.cpp