-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleGrid.php
65 lines (53 loc) · 1.26 KB
/
ExampleGrid.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
ob_start();
echo "<style>*{font-family:monospace;font-size:50px;}</style>";
$grid = [
"|........................",
"|........................",
"|........................",
"|........................",
"|........................",
"|........................",
"|........................",
"|........................",
"|........................",
"|........................",
"|________________________"
];
function grid($x,$y,$grd){
$gy = (count($grd) - $y)-1;
return substr($grd[$gy],$x,1);
}
function plot($x,$y,$char,$grd){
$gy = (count($grd) - $y) - 1;
$grd[$gy]=substr_replace($grd[$gy],$char,$x,1);
return $grd;
}
function addYnums($grd){
for ($i = 0; $i < count($grd); ++$i) {
$grd = plot(0,$i,$i,$grd);
}
return $grd;
}
$mabbr = ['J','F','M','A','M','J','J','A','S','O','N','D'];
$cplot = 2;
foreach($mabbr as $month){
$grid = plot($cplot,0,$month,$grid);
$cplot = $cplot + 2;
}
$cplot = 2;
$grid = addYnums($grid);
$eqiv = [9,5,6,7,2,3,3,4,5,0,7,2];
foreach($eqiv as $value){
$current = 1;
$value ++;
while($current < $value){
$grid = plot($cplot,$current,'X',$grid);
$current ++;
}
$cplot = $cplot + 2;
}
foreach($grid as $row){
$x = str_replace('.',' ',$row);
echo str_replace('X','<span style="color:red;">X</span>',$x).'<br />';
}