Last active
December 2, 2017 10:08
-
-
Save amnich/2e98314b8503c3724d5a8cf8275f8996 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
$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