File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Failedcode \Aoc2022 \Days ;
4
+
5
+ class Day6 extends AbstractDay
6
+ {
7
+ public function solve_part_1 (): string
8
+ {
9
+ $ input = $ this ->util ->loadInput (6 )[0 ];
10
+ return $ this ->getSignalLengthPosition ($ input , 4 );
11
+ }
12
+
13
+ public function solve_part_2 (): string
14
+ {
15
+ $ input = $ this ->util ->loadInput (6 )[0 ];
16
+ return $ this ->getSignalLengthPosition ($ input , 14 );
17
+ }
18
+
19
+ protected function getSignalLengthPosition ($ input , $ signalLength )
20
+ {
21
+ for ($ i = 0 ; $ i < $ signalLength ; $ i += 1 ) {
22
+ $ signals [] = substr ($ input , $ i , 1 );
23
+ }
24
+ for ($ i = $ signalLength ; $ i < strlen ($ input ); $ i += 1 ) {
25
+ if (count (array_unique ($ signals )) === $ signalLength ) {
26
+ return $ i ;
27
+ }
28
+ $ signals [] = substr ($ input , $ i , 1 );
29
+ array_shift ($ signals );
30
+ }
31
+ return "Error: no position found " ;
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments