Newer
Older
Import / web / www.xiaofrog.com / games / target / target-1.php
<?php

/*
    Target Word Game - Solve Puzzle
    (C) Copyright 2007
    John Ryland <jryland@invertedlogic.com>

    ALL RIGHTS RESERVED
*/

$arg = $_GET['puzzle'];
$key = substr($arg,4,1);
$arg = '['.$arg.']';
//print $HTTP_POST_VARS['puzzle'];

exec('grep -i "^\('.$arg.'\)*$" ./possible-words.txt | grep -i ' . $key, $candidates); 


foreach ($candidates as $j => $candidate) {
    $letters = str_split(strtoupper($candidate));
    $okay_arg = str_split($arg);

    foreach ($okay_arg as $okay) {
        foreach ($letters as $i => $letter) {
            if ( $okay == $letter ) {
                unset($letters[$i]);
                break;
            }
        }
    }
    if ( count($letters) != 0 ) {
        unset($candidates[$j]);
    } else {
        if ( strlen($candidate) == 9) {
            echo "The 9 letter word that can be made with the letters is: <p>";
            echo $candidate;
            echo "<p>";
        }
    }
}

echo "The possible words that can be made with the letters are: <p>";

echo implode( ", ", $candidates );

?>