Skip to content

Instantly share code, notes, and snippets.

@amnich
Last active December 2, 2017 10:08
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/2e98314b8503c3724d5a8cf8275f8996 to your computer and use it in GitHub Desktop.
Save amnich/2e98314b8503c3724d5a8cf8275f8996 to your computer and use it in GitHub Desktop.
$in = Get-Content C:\temp\day2.txt
#Day 2-1
$checksum = 0
foreach ($row in $in){
$row = $row -split "`t" | ForEach-Object {[int]$PSItem} | Sort-Object
$checksum += $row[-1] - $row[0]
}
$checksum
#Day 2-2
$checksum = 0
foreach ($row in $in){
$row = $row -split "`t"
foreach ($element in $row){
$e2 = $row | Where-Object {$_ -ne $element} | Where-Object {$PSItem % $element -eq 0}
if ($e2){
$checksum += $e2 / $element
break
}
}
}
$checksum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment