day01: Solve puzzles

main
Elis Hirwing 10 months ago
parent 74b642837c
commit 5f709fddd0
Signed by: etu
GPG Key ID: D57EFA625C9A925F
  1. 2
      Makefile
  2. 10
      day01/example.txt
  3. 2000
      day01/input.txt
  4. 38
      day01/solve.php

@ -3,6 +3,8 @@
all: day01 day02 day03 day04 day05 day06 day07 day08 day09 day10 day11 day12 day13 day14 day15 day16 day17 day18 day19 day20 day21 day22 day23 day24 day25
day01:
php day01/solve.php input
day02:
day03:
day04:

@ -0,0 +1,10 @@
199
200
208
210
200
207
240
269
260
263

File diff suppressed because it is too large Load Diff

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
require_once(__DIR__.'/../lib/functions.php');
$entries = getLines(__DIR__.'/'.$argv[1].'.txt');
timedPrintf(
'[2021-12-01.1] Amount of increases: %d [Time: %ss]',
(function (array $entries) : int {
$incs = 0;
for ($i = 0; $i < count($entries) - 1; $i++) {
if ($entries[$i] < $entries[$i + 1]) {
$incs++;
}
}
return $incs;
}),
$entries
);
timedPrintf(
'[2021-12-01.2] Amount of increases: %d [Time: %ss]',
(function (array $entries) : int {
$incs = 0;
for ($i = 0; $i < count($entries) - 3; $i++) {
if ($entries[$i] < $entries[$i + 3]) {
$incs++;
}
}
return $incs;
}),
$entries
);
Loading…
Cancel
Save