7th day both parts
This commit is contained in:
13
07/part1.php
Normal file
13
07/part1.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
$input = file('input', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
$input = explode(',', $input[0]);
|
||||
|
||||
$minFuelCost = INF;
|
||||
foreach ($input as $newPosition) {
|
||||
$fuelCost = array_sum(array_map(fn($currentPosition) => abs($currentPosition - $newPosition), $input));
|
||||
|
||||
if ($fuelCost < $minFuelCost) {
|
||||
$minFuelCost = $fuelCost;
|
||||
}
|
||||
}
|
||||
echo $minFuelCost; //328187
|
||||
Reference in New Issue
Block a user