Created
January 23, 2012 21:40
-
-
Save kaja47/1665665 to your computer and use it in GitHub Desktop.
Scrabble.php
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 | |
$letters = array( | |
'a' => 1, 'é' => 3, 'k' => 1, 'r' => 1, 'ů' => 4, | |
'á' => 2, 'ě' => 3, 'l' => 1, 'ř' => 4, 'v' => 1, | |
'b' => 3, 'f' => 5, 'm' => 2, 's' => 1, 'x' => 10, | |
'c' => 2, 'g' => 5, 'n' => 1, 'š' => 4, 'y' => 2, | |
'č' => 4, 'h' => 2, 'ň' => 6, 't' => 1, 'ý' => 4, | |
'd' => 1, 'i' => 1, 'o' => 1, 'ť' => 7, 'z' => 2, | |
'ď' => 8, 'í' => 2, 'ó' => 7, 'u' => 2, 'ž' => 4, | |
'e' => 1, 'j' => 2, 'p' => 1, 'ú' => 5); | |
$words = array_map('trim', file('seznam_slov')); | |
$wordsScore = array(); | |
foreach ($words as $w) { | |
$points = 0; | |
for ($i = 0; $i < mb_strlen($w, 'utf8'); $i++) { | |
$ch = mb_substr($w, $i, 1, 'utf8'); | |
if (isset($letters[$ch])) $points += $letters[$ch]; // else nothing | |
} | |
$wordsScore[$w] = $points; | |
} | |
arsort($wordsScore); | |
var_dump(array_slice($wordsScore, 0, 10)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment