✨ Finit le jour 4
This commit is contained in:
parent
1e84b70b7a
commit
f0609cd245
17
day_4/part_1.php
Normal file
17
day_4/part_1.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
$elves = explode("\n", file_get_contents('./input.txt'));
|
||||
|
||||
echo count(
|
||||
array_filter(
|
||||
$elves,
|
||||
static function($elf) {
|
||||
[$section1, $section2] = array_map(static fn($section) => explode('-', $section), explode(',', $elf));
|
||||
return
|
||||
($section2[0] >= $section1[0] && $section2[1] <= $section1[1])
|
||||
||
|
||||
($section1[0] >= $section2[0] && $section1[1] <= $section2[1])
|
||||
;
|
||||
}
|
||||
)
|
||||
);
|
15
day_4/part_2.php
Normal file
15
day_4/part_2.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
$elves = explode("\n", file_get_contents('./input.txt'));
|
||||
|
||||
echo count(
|
||||
array_filter(
|
||||
$elves,
|
||||
static function($elf) {
|
||||
[$section1, $section2] = array_map(static fn($section) => explode('-', $section), explode(',', $elf));
|
||||
return count(
|
||||
array_intersect(range($section1[0], $section1[1]), range($section2[0], $section2[1]))
|
||||
) > 0;
|
||||
}
|
||||
)
|
||||
);
|
Loading…
Reference in New Issue
Block a user