From 4cefe6105658b9aa78f3d713b59bba9217d000a3 Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Fri, 6 Dec 2019 14:32:52 +0100 Subject: [PATCH] :tada: Hello world --- .gitignore | 2 ++ day_1/part_1.php | 9 +++++++ day_1/part_2.php | 19 +++++++++++++++ day_2/part_1.php | 26 ++++++++++++++++++++ day_2/part_2.php | 46 +++++++++++++++++++++++++++++++++++ day_4/part_1.php | 59 +++++++++++++++++++++++++++++++++++++++++++++ day_4/part_2.php | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 224 insertions(+) create mode 100644 .gitignore create mode 100644 day_1/part_1.php create mode 100644 day_1/part_2.php create mode 100644 day_2/part_1.php create mode 100644 day_2/part_2.php create mode 100644 day_4/part_1.php create mode 100644 day_4/part_2.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5a90de --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +input.txt +/.idea \ No newline at end of file diff --git a/day_1/part_1.php b/day_1/part_1.php new file mode 100644 index 0000000..9eda71f --- /dev/null +++ b/day_1/part_1.php @@ -0,0 +1,9 @@ + 0) { + $mass = max(get_fuel_from_mass($mass), 0); + $total_fuel += $mass; + } + return $total_fuel; + }, $masses) +); \ No newline at end of file diff --git a/day_2/part_1.php b/day_2/part_1.php new file mode 100644 index 0000000..6889cf0 --- /dev/null +++ b/day_2/part_1.php @@ -0,0 +1,26 @@ + $big_number[$i]) { + return false; + } + $current_number = $big_number[$i]; + } + + return true; +} + +/** + * @param int|string $number + * + * @return bool + */ +function is_valid($number) +{ + return has_at_least_two_adjacent_number($number) && never_decrease($number); +} + +$valids = []; +for ($i = $min; $i <= $max; $i++) { + if (is_valid($i)) { + $valids[] = $i; + } +} + +echo count($valids); \ No newline at end of file diff --git a/day_4/part_2.php b/day_4/part_2.php new file mode 100644 index 0000000..db2e34c --- /dev/null +++ b/day_4/part_2.php @@ -0,0 +1,63 @@ + $big_number[$i]) { + return false; + } + $current_number = $big_number[$i]; + } + + return true; +} + +/** + * @param int|string $number + * + * @return bool + */ +function is_valid($number) +{ + return has_no_more_than_two_adjacent_number($number) && never_decrease($number); +} + +$valids = []; +for ($i = $min; $i <= $max; $i++) { + if (is_valid($i)) { + $valids[] = $i; + } +} + +echo count($valids); // more than 574 & less than 1099 \ No newline at end of file