Skip to content

Instantly share code, notes, and snippets.

@kaja47
Created January 23, 2012 21:40
Show Gist options
  • Save kaja47/1665665 to your computer and use it in GitHub Desktop.
Save kaja47/1665665 to your computer and use it in GitHub Desktop.
Scrabble.php
<?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