File tree Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ ifeq ($(shell docker image inspect $(image-name) > /dev/null 2>&1 || echo not_ex
90
90
make run
91
91
else
92
92
ifneq ("$(wildcard vendor) ", "")
93
- @$(DOCKER_RUN_PHP_MY_IMAGE) $(image-name) php -dopcache.enable_cli=1 -dopcache.jit_buffer_size=100M -dopcache.jit=1255 run.php $(onlyThis)
93
+ @$(DOCKER_RUN_PHP_MY_IMAGE) $(image-name) php -dmemory_limit=4G - dopcache.enable_cli=1 -dopcache.jit_buffer_size=100M -dopcache.jit=1255 run.php $(onlyThis)
94
94
else
95
95
@echo -e "\nFirst run detected! No vendor/ folder found, running composer update...\n"
96
96
make composer
Original file line number Diff line number Diff line change @@ -10,8 +10,6 @@ class Day15 extends DayBehaviour implements DayInterface
10
10
{
11
11
public function solvePart1 (): int |string |null
12
12
{
13
- //$this->input[0] = '0,3,6';
14
- //$this->input[0] = '3,1,2';
15
13
$ turns = array_map ('intval ' , str_getcsv (trim ($ this ->input [0 ])));
16
14
$ max = 2020 ;
17
15
$ i = count ($ turns );
@@ -33,7 +31,35 @@ public function solvePart1(): int|string|null
33
31
34
32
public function solvePart2 (): int |string |null
35
33
{
36
- // TODO: Implement solvePart2() method.
37
- return null ;
34
+ // this takes 12s and uses 1.42gb of memory!
35
+ //return 1065;
36
+ $ turns = array_map ('intval ' , str_getcsv (trim ($ this ->input [0 ])));
37
+ $ max = 30000000 ;
38
+ $ i = count ($ turns );
39
+
40
+ // <no => [turn2,turn1]>
41
+ $ mem = [];
42
+ $ last = 0 ;
43
+ // seed with starting numbers, turn always starts from 1
44
+ foreach ($ turns as $ k => $ t ) {
45
+ $ mem [$ t ] = [$ k + 1 ];
46
+ $ last = $ t ;
47
+ }
48
+
49
+ while ($ i < $ max ) {
50
+ // loop backwards from end of array
51
+ if (1 === count ($ mem [$ last ])) {
52
+ $ next = 0 ;
53
+ } else {
54
+ $ next = $ mem [$ last ][1 ] - $ mem [$ last ][0 ];
55
+ $ mem [$ last ] = array_slice ($ mem [$ last ], -2 );
56
+ }
57
+ $ mem [$ next ][] = $ i + 1 ;
58
+ $ mem [$ next ] = array_slice ($ mem [$ next ], -2 );
59
+ $ last = $ next ;
60
+ ++$ i ;
61
+ }
62
+
63
+ return $ last ;
38
64
}
39
65
}
Original file line number Diff line number Diff line change 17
17
18
18
test ('solves part2 ' )
19
19
->expect (fn () => $ this ->day ->solvePart2 ())
20
- ->toBe (null )
20
+ ->toBe (1065 )
21
21
;
You can’t perform that action at this time.
0 commit comments