コード例 #1
0
ファイル: index.php プロジェクト: jmilagroso/braille-solver
    {
        foreach ($this->braille_str_lines as $lines) {
            $this->exploded_lines[] = str_replace(["\n"], [""], explode(" ", $lines));
        }
    }
    private function flattenBrailleChars()
    {
        $flattenedChar = [];
        for ($i = 0; $i <= count($this->exploded_lines[0]) - 1; $i++) {
            for ($j = 0; $j <= 2; $j++) {
                $flattenedChar[] = trim($this->exploded_lines[$j][$i]);
            }
            $this->chars[] = implode("", $flattenedChar);
            $flattenedChar = [];
        }
    }
    public function solve()
    {
        $this->breakToThreeLines();
        $this->breakRow();
        $this->flattenBrailleChars();
        $word = '';
        foreach ($this->chars as $value) {
            $word .= $this->braille_table[$value];
        }
        echo $word;
    }
}
$s = new Solver($braille_str, $braille_table);
echo $s->solve();
コード例 #2
0
ファイル: search.php プロジェクト: pbedorf/demo
<?

require 'Solver.php';

try{
    // You probably want to change this
    $db = new PDO('mysql:host=localhost;dbname=anagram', 'root', 'root');

    $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); // Throw exceptions
}catch(PDOException $e){
    die('Database on fire. ('. $e->getMessage() . ')');
}

$slvr = new Solver($db);
$slvr->solve($_GET['q'], $_GET['lang']);
コード例 #3
0
ファイル: day17.php プロジェクト: zoem/adventofcode
<?php

$input = file_get_contents('day17.txt');
$lines = explode("\r\n", $input);
$lines = array_filter($lines);
$containers = [];
foreach ($lines as $line) {
    $containers[] = intval($line);
}
$solver = new Solver();
$ans = $solver->solve($containers, 150);
printf('ans#17.1: %u' . PHP_EOL, $ans[1]);
printf('ans#17.2: %u' . PHP_EOL, $ans[2]);
class Solver
{
    public $used = [];
    public $found = 0;
    public $foundMin = 0;
    public $min;
    public $max;
    public function solve($values, $max)
    {
        $this->used = [];
        $this->min = count($values);
        $this->max = $max;
        while ($values) {
            end($values);
            $key = key($values);
            $node = new Node($key, array_pop($values));
            $this->doSolve($values, $node, 150);
        }
コード例 #4
0
 private function _whenSolvingFor($puzzle)
 {
     $this->_solution = $this->_solver->solve($this->_grid, $puzzle);
 }