Skip to content

Instantly share code, notes, and snippets.

@smortex
Created December 2, 2022 17:36
Show Gist options
  • Save smortex/42f79bc7db8d0344338affd5027e1276 to your computer and use it in GitHub Desktop.
Save smortex/42f79bc7db8d0344338affd5027e1276 to your computer and use it in GitHub Desktop.
Advent of Code 2022 - Day 2
$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 })
@pier4r
Copy link

pier4r commented Dec 2, 2022

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