Skip to content

Instantly share code, notes, and snippets.

@tech-zombie
Created December 1, 2022 23:45
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 tech-zombie/7a339474e17c3289369245f55e8a0076 to your computer and use it in GitHub Desktop.
Save tech-zombie/7a339474e17c3289369245f55e8a0076 to your computer and use it in GitHub Desktop.
$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