Created
December 1, 2022 23:45
-
-
Save tech-zombie/7a339474e17c3289369245f55e8a0076 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
$calList = gc input.txt | |
$calorieTotal = 0 | |
$elfNumber = 0 | |
$elves = foreach ($package in $callist) | |
{ | |
if ($package -eq ''){ | |
#record calories and zero total | |
[PSCustomObject]@{ | |
Elf = $elfNumber | |
TotalCalories = $calorieTotal | |
} | |
$elfNumber++ | |
$calorieTotal = 0 | |
} | |
$calorieTotal = $calorieTotal + $package | |
} | |
'Part1 ' + ($elves | sort TotalCalories -descending | select -first 1).TotalCalories | |
'Part2 ' + ($elves | sort TotalCalories -descending | select TotalCalories -first 3 | measure-object TotalCalories -sum | select sum).sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment