Last active
April 13, 2018 14:58
-
-
Save carlosbelisario/3cf311651b76e2906f97e572c1fe73e6 to your computer and use it in GitHub Desktop.
Casi Palindromes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('NECESARY_CHANGES', 3); | |
/** | |
* @param string $string | |
* @return bool | |
*/ | |
function palindrome($string) { | |
$revert = strrev($string); | |
$length = strlen($string); | |
return $length > 1 && (levenshtein($string, $revert) < NECESARY_CHANGES); | |
} | |
/** | |
* @test | |
*/ | |
function testPalindrome(array $words) | |
{ | |
foreach($words as $word) { | |
if (palindrome($word)) { | |
echo "it is almost palindrome \n"; | |
} else { | |
echo "failure: the word: " . $word . " is not palindrome \n"; | |
} | |
} | |
} | |
$words = ['reconocer', 'oso', 'arepera', 'osao', 'hola']; | |
testPalindrome($words); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment