Skip to content

Commit 33e227b

Browse files
committed
Day 10, part2
1 parent afcf357 commit 33e227b

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/Days/Day10.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,34 @@ public function solve_part_1(): string
2828

2929
public function solve_part_2(): string
3030
{
31-
return "TODO";
31+
$width = 40;
32+
$height = 6;
33+
$changes = $this->getRegisterChanges();
34+
$screen = array_fill(0, $width*$height, ' ');
35+
$x = $cycle = 1;
36+
foreach ($changes as $change) {
37+
if ($this->isInRange( ($cycle % $width)-1, $x-1, $x+1)) {
38+
$screen[$cycle-1] = '';
39+
}
40+
$x += $change;
41+
$cycle += 1;
42+
}
43+
echo "\n";
44+
for ($y = 0; $y < $height; $y += 1) {
45+
$line = implode('', array_slice($screen, $y*$width, $width-1));
46+
echo " {$y} {$line}\n";
47+
}
48+
echo " ";
49+
for ($x = 0; $x < $width; $x += 1) {
50+
echo $x % 10;
51+
}
52+
echo "\n\n";
53+
return "TODO: OCR";
54+
}
55+
56+
protected function isInRange($x, $start, $end)
57+
{
58+
return $x >= $start && $x <= $end;
3259
}
3360

3461
protected function getRegisterChanges()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy