Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Levenshtein distance 1
<?php
function getLevenshtein1($word)
{
$words = array();
for ($i = 0; $i < strlen($word); $i++) {
// insertions
$words[] = substr($word, 0, $i) . '_' . substr($word, $i);
// deletions
$words[] = substr($word, 0, $i) . substr($word, $i + 1);
// substitutions
$words[] = substr($word, 0, $i) . '_' . substr($word, $i + 1);
}
// last insertion
$words[] = $word . '_';
return $words;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.