advent_of_code_2019/day_8/part_1.php

25 lines
580 B
PHP
Raw Normal View History

2019-12-09 11:57:44 +01:00
<?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'];