🎉 Starts day 1
This commit is contained in:
commit
db1e4575c7
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/.idea
|
19
add
Executable file
19
add
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
|
12
day_1/part_1.php
Normal file
12
day_1/part_1.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$lines = array_filter(explode("\n", file_get_contents('./input.txt')), fn($line) => !empty($line));
|
||||||
|
|
||||||
|
echo array_sum(array_map(
|
||||||
|
static function($line) {
|
||||||
|
$numbers = array_values(array_filter(array_map(static fn($letter) => is_numeric($letter) ? $letter : null, str_split($line))));
|
||||||
|
|
||||||
|
return (int) sprintf('%s%s', $numbers[0], array_pop($numbers));
|
||||||
|
},
|
||||||
|
$lines
|
||||||
|
));
|
Loading…
Reference in New Issue
Block a user