Esempio n. 1
0
function showcats($fields)
{
    global $settings;
    global $cat_table;
    //iTunes Categories
    $allcats = array($settings['feedcat1'], $settings['feedcat2'], $settings['feedcat3'], $settings['feedcat4']);
    $tunecats = "";
    $catsarray = array();
    /*if (filled($fields['category1_id'])) { 
            $tunecats .= urldecode(getcategory($fields['category1_id'])) . ", "; 
            $catsarray[1] = urldecode(getcategory($fields['category1_id'])); }
        if (filled($fields['category2_id'])) { 
            $tunecats .= urldecode(getcategory($fields['category2_id'])) . ", ";
            $catsarray[2] = urldecode(getcategory($fields['category2_id'])); }
        if (filled($fields['category3_id'])) { 
            $tunecats .= urldecode(getcategory($fields['category3_id'])) . ", ";
            $catsarray[3] = urldecode(getcategory($fields['category3_id'])); }
        if (filled($fields['category4_id'])) { 
            $tunecats .= urldecode(getcategory($fields['category4_id'])) . ", ";
            $catsarray[4] = urldecode(getcategory($fields['category4_id'])); }
    	*/
    if (filled($fields['tags'])) {
        $tunecats = "displayTags";
        $catsarray = explode(' ', $fields['tags']);
        unset($catsarray[count($catsarray) - 1]);
    }
    $regcats = "";
    if (filled($tunecats)) {
        foreach ($catsarray as $thiscat) {
            $regcats .= "    <category>" . html_to_xml($thiscat) . "</category>\n";
        }
    } else {
        foreach ($allcats as $thiscat) {
            if (filled($cat_table[$thiscat])) {
                $tunecats .= $cat_table[$thiscat] . ", ";
                $regcats .= "    <category>" . $cat_table[$thiscat] . "</category>\n";
            }
        }
    }
    //trim the string
    $tunecats = str_replace("&", "&amp;", trim(substr($tunecats, 0, strrpos($tunecats, ","))));
    $tunecats = "    <itunes:keywords>" . $tunecats . "</itunes:keywords>\n";
    echo $tunecats . $regcats;
}
function solve($board)
{
    // get empty spaces, find one with one choice, set it , rinse and repeat
    while (!filled($board) && !validSolution($board)) {
        for ($i = 0; $i < 9; $i++) {
            for ($j = 0; $j < 9; $j++) {
                if ($board[$i][$j] == 0) {
                    $valid = validValuesFor($board, [$i, $j]);
                    if (count($valid) == 1) {
                        $board[$i][$j] = $valid[0];
                    }
                }
            }
        }
    }
    return $board;
}
 public function test_filled()
 {
     $this->assertEquals(false, filled([[5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1, 9, 0, 0, 5], [0, 0, 0, 0, 8, 0, 0, 7, 9]]));
     $this->assertEquals(true, filled([[5, 3, 4, 6, 7, 8, 9, 1, 2], [6, 7, 2, 1, 9, 5, 3, 4, 8], [1, 9, 8, 3, 4, 2, 5, 6, 7], [8, 5, 9, 7, 6, 1, 4, 2, 3], [4, 2, 6, 8, 5, 3, 7, 9, 1], [7, 1, 3, 9, 2, 4, 8, 5, 6], [9, 6, 1, 5, 3, 7, 2, 8, 4], [2, 8, 7, 4, 1, 9, 6, 3, 5], [3, 4, 5, 2, 8, 6, 1, 7, 9]]));
 }