File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Failedcode \Aoc2022 \Days ;
4
+
5
+ class Day10 extends AbstractDay
6
+ {
7
+ public function solve_part_1 (): string
8
+ {
9
+ $ changes = $ this ->getRegisterChanges ();
10
+ $ cycleSave = [
11
+ 20 => 0 ,
12
+ 60 => 0 ,
13
+ 100 => 0 ,
14
+ 140 => 0 ,
15
+ 180 => 0 ,
16
+ 220 => 0 ,
17
+ ];
18
+ $ x = $ cycle = 1 ;
19
+ foreach ($ changes as $ change ) {
20
+ if (array_key_exists ($ cycle , $ cycleSave )) {
21
+ $ cycleSave [$ cycle ] = $ x * $ cycle ;
22
+ }
23
+ $ x += $ change ;
24
+ $ cycle += 1 ;
25
+ }
26
+ return array_reduce ($ cycleSave , function ($ c , $ v ){ return $ c + $ v ; });
27
+ }
28
+
29
+ public function solve_part_2 (): string
30
+ {
31
+ return "TODO " ;
32
+ }
33
+
34
+ protected function getRegisterChanges ()
35
+ {
36
+ $ register = [];
37
+ $ inputList = array_filter ($ this ->util ->loadInput (10 ), 'strlen ' );
38
+ foreach ($ inputList as $ row ) {
39
+ if (trim ($ row ) === 'noop ' ) {
40
+ $ register [] = 0 ;
41
+ continue ;
42
+ }
43
+ if (preg_match ('~addx (-?\d+)~ ' , $ row , $ match )) {
44
+ $ register [] = 0 ;
45
+ $ register [] = (int )$ match [1 ];
46
+ }
47
+ }
48
+ return $ register ;
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments