-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.php
executable file
·28 lines (27 loc) · 988 Bytes
/
solution.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
#!/usr/bin/env php
<?php
include("common.php");
$lines = read_input();
$points = []; foreach($lines as $line) $points[]=line2digits($line);
$minwh = 999999; $grid = [];
foreach(range(0,11000) as $step){
$xpoints = []; $ypoints = [];
foreach($points as $p) {
$xpoints[]= $p[0] + $step*$p[2];
$ypoints[]= $p[1] + $step*$p[3];
}
$xmin = Amin($xpoints)-2; $xmax = Amax($xpoints)+2;
$ymin = Amin($ypoints)-2; $ymax = Amax($ypoints)+2;
$w = ($xmax - $xmin); $h = ($ymax - $ymin);
$wh = $w*$h;
if($w>80 || $h>80) continue;
if($wh>$minwh)break;
$minwh = $wh;
printf("Seconds: %5d , width: %d , height: %d , ".
"xmin: %d, ymin: %d, xmax: %d, ymax: %d, wh: %d\n",
$step, $w, $h,
$xmin, $ymin, $xmax, $ymax, $wh);
$grid = A2Dnew($w, $h, SPACE_EMPTY);
foreach($xpoints as $k=>$x) $grid[ $ypoints[$k] - $ymin ] [ $x - $xmin ] = SPACE_FILLED;
}
foreach($grid as $gx) echo join('',$gx)."\n";