Add day 12 part 1

This commit is contained in:
2019-12-12 14:09:52 +01:00
parent 1273f4388b
commit 1ac5b20e1e
4 changed files with 301 additions and 0 deletions

21
day_12/part_1.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
include 'Moon.php';
include 'Velocity.php';
include 'functions.php';
$moons = array_map(function ($moon) {
$moon_coordinates = explode(', ', substr($moon, 1, -1));
$x = (int) substr($moon_coordinates[0], 2);
$y = (int) substr($moon_coordinates[1], 2);
$z = (int) substr($moon_coordinates[2], 2);
return new Moon($x, $y, $z);
}, explode("\n", file_get_contents('input.txt'))
);
for ($i = 0; $i < 1000; $i++) {
calculateVelocity($moons);
updateCoordinates($moons);
}
var_dump(calculateEnergy($moons));