Finit le jour 3

This commit is contained in:
2021-12-03 12:35:42 +01:00
parent 0dc0c90964
commit 75f245787b
2 changed files with 68 additions and 0 deletions

16
day_3/part_1.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
$lines = array_map('str_split', explode("\n", file_get_contents('input.txt')));
$lines = array_map('array_reverse', array_map(null, ...$lines)); // matrix rotation
$gamma = '';
$epsilon = '';
foreach ($lines as $line) {
$counts = array_count_values($line);
$max = array_search(max($counts), $counts);
$gamma .= $max;
$epsilon .= $max === 1 ? 0 : 1;
}
echo bindec($gamma) * bindec($epsilon);