You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

25 lines
580 B

<?php
$input = file_get_contents('input.txt');
const WIDTH = 25;
const HEIGHT = 6;
$area = WIDTH * HEIGHT;
$layers = array_map(static function($layer) {
return str_split($layer);
}, str_split($input, $area));
usort($layers, function($layer_a, $layer_b) {
$a0 = array_count_values($layer_a)['0'];
$b0 = array_count_values($layer_b)['0'];
if ($a0 === $b0) {
return 0;
}
return $a0 < $b0 ? -1 : 1 ;
});
reset($layers);
$fewest_0_layer = current($layers);
echo array_count_values($fewest_0_layer)['1'] * array_count_values($fewest_0_layer)['2'];