🎉 initialise le repo comme en 2020 et 2019

This commit is contained in:
2021-12-01 17:04:58 +01:00
commit a6efae14f9
4 changed files with 54 additions and 0 deletions

15
day_1/part_1.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
$numbers = array_map('intval', explode("\n", file_get_contents('input.txt')));
$current = array_shift($numbers);
$count = 0;
foreach ($numbers as $number) {
if ($number > $current) {
$count++;
}
$current = $number;
}
echo $count;

18
day_1/part_2.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
$numbers = array_map('intval', explode("\n", file_get_contents('input.txt')));
$current_slice = array_sum(array_slice($numbers, 0, 3));
$count = 0;
for ($i = 1, $l = count($numbers) - 3; $i <= $l; $i++) {
$new_slice = array_sum(array_slice($numbers, $i, 3));
if ($new_slice > $current_slice) {
$count++;
}
$current_slice = $new_slice;
}
echo $count;