advent_of_code_2019/day_12/part_1.php

22 lines
562 B
PHP

<?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));