advent_of_code_2022/day_4/part_2.php

16 lines
425 B
PHP
Raw Normal View History

2022-12-06 10:12:35 +01:00
<?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;
}
)
);