Created
December 13, 2017 00:23
-
-
Save TsuiAnthonYVR/0ae779b5d1ae494273e1a2cfa522cb05 to your computer and use it in GitHub Desktop.
Day 1 Part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$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