Last active
December 1, 2017 08:53
-
-
Save amnich/0b4ee952e62b872cab89c98068fb04a3 to your computer and use it in GitHub Desktop.
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
function Day1 { | |
param ($sequence, $offset) | |
[int]$sum = 0 | |
for ($i=0; $i -lt $sequence.Length; $i++){ | |
$k = $i + $offset | |
if ($k -ge $sequence.Length){ | |
$k = $k - $sequence.Length | |
} | |
if ([int]$sequence[$i] -eq [int]$sequence[$k]){ | |
$sum += [int][string]$sequence[$i] | |
} | |
} | |
$sum | |
} | |
$sequence = '1212' | |
#Day 1-1 | |
Day1 -sequence $sequence -offset 1 | |
#Day 1-2 | |
Day1 -sequence $sequence -offset $($sequence.Length / 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment