advent_of_code_2019/day_1/part_2.php
2019-12-06 14:32:52 +01:00

19 lines
382 B
PHP

<?php
$masses = explode(',', file_get_contents('input.txt'));
function get_fuel_from_mass($mass)
{
return floor($mass / 3) - 2;
}
echo array_sum(
array_map(function($mass) {
$total_fuel = 0;
while($mass > 0) {
$mass = max(get_fuel_from_mass($mass), 0);
$total_fuel += $mass;
}
return $total_fuel;
}, $masses)
);