tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
15
Task/Semordnilap/PHP/semordnilap.php
Normal file
15
Task/Semordnilap/PHP/semordnilap.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
// Read dictionary into array
|
||||
$dictionary = array_fill_keys(file(
|
||||
'http://www.puzzlers.org/pub/wordlists/unixdict.txt',
|
||||
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
|
||||
), true);
|
||||
foreach (array_keys($dictionary) as $word) {
|
||||
$reversed_word = strrev($word);
|
||||
if (isset($dictionary[$reversed_word]) && $word > $reversed_word)
|
||||
$words[$word] = $reversed_word;
|
||||
}
|
||||
echo count($words), "\n";
|
||||
// array_rand() returns keys, not values
|
||||
foreach (array_rand($words, 5) as $word)
|
||||
echo "$word $words[$word]\n";
|
||||
Loading…
Add table
Add a link
Reference in a new issue