-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.php
38 lines (29 loc) · 851 Bytes
/
run.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
include 'vendor/autoload.php';
// Create our classes
$grid = new \Andywaite\Sudoku\Grid();
$printer = new \Andywaite\Sudoku\GridPrinter();
$solver = new \Andywaite\Sudoku\HackyButFast();
$gridLoader = new \Andywaite\Sudoku\GridLoader();
// Load start grid from file
$gridLoader->loadGrid($grid, 'examples/hardest.txt');
// Echo unsolved state so we can see the "before"
echo "\nUnsolved";
$printer->printGrid($grid);
// Solve!
$start = microtime(true);
try {
if (!$solver->solve($grid)) {
throw new Exception("Solver returned false");
}
echo "\n\nSolved";
} catch (Exception $e) {
echo "\n\nFailed to solve: ".$e->getMessage();
}
// Calculate timings
$end = microtime(true);
$runTime = ($end - $start);
// Show the completed grid
$printer->printGrid($grid);
// Show exec time
echo "\nExecution: ".$runTime."\n";