Skip to content

Instantly share code, notes, and snippets.

@amnich
Last active December 1, 2017 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amnich/0b4ee952e62b872cab89c98068fb04a3 to your computer and use it in GitHub Desktop.
Save amnich/0b4ee952e62b872cab89c98068fb04a3 to your computer and use it in GitHub Desktop.
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