3rd and 2nd day
This commit is contained in:
11
03/part2.php
Normal file
11
03/part2.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
$input = file('input', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
$input = array_map(fn($line) => str_split($line), $input);
|
||||
$gamma = $epsilon = [];
|
||||
for ($i = 0; $i < count($input[0]); $i++) {
|
||||
$bit = (int) (array_sum($column = array_column($input, $i)) >= ceil(count($column) / 2));
|
||||
$gamma[] = $bit;
|
||||
$epsilon[] = ~$bit & 1;
|
||||
}
|
||||
echo bindec(implode('', $gamma)) * bindec(implode('', $epsilon)).PHP_EOL;
|
||||
Reference in New Issue
Block a user