🎉 initialise le repo comme en 2020 et 2019
This commit is contained in:
15
day_1/part_1.php
Normal file
15
day_1/part_1.php
Normal 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
18
day_1/part_2.php
Normal 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;
|
Reference in New Issue
Block a user