✨ Finit le jour 3
This commit is contained in:
16
day_3/part_1.php
Normal file
16
day_3/part_1.php
Normal 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);
|
Reference in New Issue
Block a user