Created
December 2, 2022 17:36
-
-
Save smortex/42f79bc7db8d0344338affd5027e1276 to your computer and use it in GitHub Desktop.
Advent of Code 2022 - Day 2
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
$data = file('aoc/2022/day2.txt') | |
$rounds = $data.split('\n').map |$line| { [$line[0], $line[2]] } | |
$scores1 = $rounds.map |$round| { | |
$shape_score = $round[1] ? { | |
'X' => 1, | |
'Y' => 2, | |
'Z' => 3, | |
} | |
$outcome_score = $round ? { | |
['A', 'X'] => 3, | |
['A', 'Y'] => 6, | |
['A', 'Z'] => 0, | |
['B', 'X'] => 0, | |
['B', 'Y'] => 3, | |
['B', 'Z'] => 6, | |
['C', 'X'] => 6, | |
['C', 'Y'] => 0, | |
['C', 'Z'] => 3, | |
} | |
$shape_score + $outcome_score | |
} | |
$scores2 = $rounds.map |$round| { | |
$outcome_score = $round[1] ? { | |
'X' => 0, | |
'Y' => 3, | |
'Z' => 6, | |
} | |
$shape_score = $round ? { | |
['A', 'X'] => 3, | |
['A', 'Y'] => 1, | |
['A', 'Z'] => 2, | |
['B', 'X'] => 1, | |
['B', 'Y'] => 2, | |
['B', 'Z'] => 3, | |
['C', 'X'] => 2, | |
['C', 'Y'] => 3, | |
['C', 'Z'] => 1, | |
} | |
$shape_score + $outcome_score | |
} | |
warning($scores1.reduce |$memo, $score| { $memo + $score }) | |
warning($scores2.reduce |$memo, $score| { $memo + $score }) |
I really have to use bolt, I thought it was a tad different but it seems like scriptable puppet. I am losing opportunities there.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@pier4r I run it through bolt for convenience but language is the same so this can also run with puppet:
The ideal would in fact be a plan, so that we do not need to pass an unneeded target 😄 :