🎉 initialise le repo comme en 2020 et 2019
This commit is contained in:
commit
a6efae14f9
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
input.txt
|
||||||
|
/.idea
|
19
add.sh
Executable file
19
add.sh
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/zsh
|
||||||
|
|
||||||
|
SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
|
||||||
|
NUMBER=$1
|
||||||
|
|
||||||
|
if [ ! -d "${SCRIPT_PATH}/day_${NUMBER}" ]; then
|
||||||
|
mkdir "${SCRIPT_PATH}/day_${NUMBER}"
|
||||||
|
else
|
||||||
|
echo "folder ${SCRIPT_PATH}/day_${NUMBER} already exists"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "${SCRIPT_PATH}/day_${NUMBER}" || exit
|
||||||
|
|
||||||
|
touch input.txt part_1.php part_2.php
|
||||||
|
|
||||||
|
echo "DONE"
|
||||||
|
|
||||||
|
exit
|
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;
|
Loading…
Reference in New Issue
Block a user