✨ Finit les part 1 du jour 2 et 3
Ouin, pas le temps de faire les part 2 😭
			
			
This commit is contained in:
		
							
								
								
									
										52
									
								
								day_2/part_1.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								day_2/part_1.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| <?php | ||||
|  | ||||
| $reports = array_filter(explode("\n", file_get_contents(__DIR__.'/input.txt')), static fn($line) =>!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; | ||||
							
								
								
									
										8
									
								
								day_3/part_1.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								day_3/part_1.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| <?php | ||||
|  | ||||
| $instruction = file_get_contents(__DIR__.'/input.txt'); | ||||
|  | ||||
| preg_match_all('/mul\((\d+),(\d+)\)/', $instruction, $muls, PREG_SET_ORDER); | ||||
|  | ||||
| echo array_sum(array_map(static fn($mul) => $mul[1]*$mul[2], $muls)); | ||||
| exit; | ||||
		Reference in New Issue
	
	Block a user
	 Clement Desmidt
					Clement Desmidt