Created
October 21, 2016 10:01
-
-
Save yvan-sraka/b679dcd687327bcd58a4a323e49bc8ed to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?hh | |
// Exercice 1 | |
$string = file_get_contents("dictionnaire.txt", FILE_USE_INCLUDE_PATH); | |
$dico = explode("\n", $string); | |
// How many words this dictionary contains? | |
echo count($dico); // answer: 336532 | |
// How many words have exactly 15 characters? | |
$words_15 = array(); | |
foreach ($dico as $word) { | |
if (strlen($word) == 15) { | |
array_push($words_15, $word); | |
} | |
} | |
echo count($words_15); // answer: 12298 | |
echo $a; | |
// How many words containing the letter ‘w’? | |
$words_w = array(); | |
foreach ($dico as $word) { | |
if (strpos($word, "w") !== false) { | |
array_push($words_w, $word); | |
} | |
} | |
echo count($words_w); // answer: 537 | |
// How many words end with the letter ‘q’? | |
$words_q = array(); | |
foreach ($dico as $word) { | |
if (substr($word, -1) == "q") { | |
array_push($words_q, $word); | |
} | |
} | |
echo count($words_q); // answer: 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment