[ create a new paste ] login | about

Link: http://codepad.org/9EQY16gO    [ raw code | output | fork ]

PHP, pasted on Dec 7:
<?php
$words = 'these are the words';
$words = explode(' ',$words);

$rack = 'a b c d e f g';
$rack = explode(' ',$rack);
$rack = array_flip($rack);

$score = array("a" => 1, "b" => 1, "c" => 1, "d" => 1, "e" => 1, "f" => 1, "g" => 1, "h" => 1, 
"i" => 1, "j" => 1, "k" => 1, "l" => 1, "m" => 1, "n" => 1, "o" => 1, "p" => 1, "q" => 1, 
"r" => 1, "s" => 1, "t" => 1, "u" => 1, "v" => 1, "w" => 1, "x" => 1, "y" => 1, "z" => 1); 

$playable = array();
$playable_score = array();

foreach($words as $val)
{
$len = strlen($val);
$thisscore = 0;
for($run=0; $run<$len; $run++)
    {
    if (isset($rack[$val[$run]]) && isset($score[$val[$run]]))
    $thisscore+=$score[$val[$run]];
    }
if ($thisscore>0)
    {
    $playable[]=$val;
    $playable_score[]=$thisscore;
    }
}
print_r($playable);
print_r($playable_score);
?>


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Array
(
    [0] => these
    [1] => are
    [2] => the
    [3] => words
)
Array
(
    [0] => 2
    [1] => 2
    [2] => 1
    [3] => 1
)


Create a new paste based on this one


Comments: