Skip to content

Instantly share code, notes, and snippets.

@mspreij
Last active December 2, 2018 16:59
Show Gist options
  • Save mspreij/a4b5922c855152c9366eedb926e2252e to your computer and use it in GitHub Desktop.
Save mspreij/a4b5922c855152c9366eedb926e2252e to your computer and use it in GitHub Desktop.
// having turned input into an array..
// Levenshtein 0.04 seconds
for ($i=0; $i < 250; $i++) {
for ($j=$i+1; $j < 250; $j++) {
if (levenshtein($input[$i], $input[$j]) == 1) {
echo $input[$i].':'.$input[$j]."\n";
}
}
}
// loops 0.4 seconds
for ($i=0; $i < 249; $i++) {
for ($j=$i+1; $j < 250; $j++) {
for ($c=0; $c < 26; $c++) {
if (substr($input[$i], 0, $c)==substr($input[$j], 0, $c) and substr($input[$i], $c+1)==substr($input[$j], $c+1)) {
echo $input[$i].' : '.$input[$j];
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment