🎉 Hello world

This commit is contained in:
2019-12-06 14:32:52 +01:00
commit 4cefe61056
7 changed files with 224 additions and 0 deletions

19
day_1/part_2.php Normal file
View File

@@ -0,0 +1,19 @@
<?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)
);