diff --git a/day_2/part_1.php b/day_2/part_1.php new file mode 100644 index 0000000..9b1be79 --- /dev/null +++ b/day_2/part_1.php @@ -0,0 +1,52 @@ +!empty($line)); + +$number_of_safe_reports = 0; +function is_report_safe(string $report) +{ + $levels = explode(' ', $report); + $current_number = null; + $current_way = null; + foreach ($levels as $level) { + if ($current_number === null) { + $current_number = $level; + } else { + if ($current_number === $level) { + return false; + } + if ($current_number > $level) { + if ($current_number - $level > 3) { + return false; + } + if ($current_way === null) { + $current_way = 'd'; + } elseif ($current_way !== 'd') { + return false; + } + } + if ($current_number < $level) { + if ($level - $current_number > 3) { + return false; + } + if ($current_way === null) { + $current_way = 'a'; + } elseif ($current_way !== 'a') { + return false; + } + } + $current_number = $level; + } + } + + return true; +} + +foreach ($reports as $report) { + if (is_report_safe($report)) { + $number_of_safe_reports++; + } +} + +echo sprintf('Number of safe reports : %u', $number_of_safe_reports); +exit; \ No newline at end of file diff --git a/day_3/part_1.php b/day_3/part_1.php new file mode 100644 index 0000000..d57ee47 --- /dev/null +++ b/day_3/part_1.php @@ -0,0 +1,8 @@ + $mul[1]*$mul[2], $muls)); +exit;