-
Notifications
You must be signed in to change notification settings - Fork 0
/
Painter.php
49 lines (45 loc) · 1.08 KB
/
Painter.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
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* @author Yurii Savka <yurii.savka@lendico.de>
* @created 08/02/16 13:59
*/
class Painter
{
/** @var PaintZone */
private $basicZone;
public function __construct(PaintZone $zone)
{
$this->basicZone = $zone;
}
public function work()
{
$lines = $this->basicZone->findAllLines();
$lines = array_merge($lines, $this->basicZone->findAllSquares());
usort(
$lines,
function ($l1, $l2) {
$a = $l1->square;
$b = $l2->square;
if ($a == $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
}
);
$zone = $this->basicZone;
$n = 0;
foreach ($lines as $line) {
$n++;
//print $line . PHP_EOL;
$zone->applyLine($line);
//$zone->out();
if ($zone->isSolved()) {
break;
}
}
print $n.PHP_EOL;
for ($i = 0; $i < $n; $i++) {
print $lines[$i].PHP_EOL;
}
}
}