Skip to content

Instantly share code, notes, and snippets.

@TsuiAnthonYVR
Created December 13, 2017 00:23
Show Gist options
  • Save TsuiAnthonYVR/0ae779b5d1ae494273e1a2cfa522cb05 to your computer and use it in GitHub Desktop.
Save TsuiAnthonYVR/0ae779b5d1ae494273e1a2cfa522cb05 to your computer and use it in GitHub Desktop.
Day 1 Part 2
<?
$original = str_split($inputString);
$characters = array_merge($original, $original);
$total = 0;
$stepsHalfWay = intval(count($original) / 2);
for ($i = 0; $i < count($original); $i++) {
$char = $characters[$i];
$match = $characters[$i + $stepsHalfWay];
if ($char === $match) {
$total += intval($char);
}
}
error_log("result is $total");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment