Skip to content

Instantly share code, notes, and snippets.

@TsuiAnthonYVR
Created December 13, 2017 00:22
Show Gist options
  • Save TsuiAnthonYVR/671e080b8bf594af173fe64daaff6967 to your computer and use it in GitHub Desktop.
Save TsuiAnthonYVR/671e080b8bf594af173fe64daaff6967 to your computer and use it in GitHub Desktop.
Day 2 Part 2
$rows = explode("\n", $xml);
$checksum = 0;
foreach ($rows as $row) {
$cells = [];
foreach (explode("|", $row) as $cell) {
$cells[] = intval($cell);
}
sort($cells);
for ($outer = 0; $outer < count($cells); $outer++) {
for ($inner = $outer + 1; $inner < count($cells); $inner++) {
if (($cells[$inner] % $cells[$outer]) == 0) {
$checksum += ($cells[$inner] / $cells[$outer]);
}
}
}
}
error_log("checksum: $checksum");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment