Signed-off-by: jolheiser <john.olheiser@gmail.com>
main
jolheiser 2022-12-02 14:49:56 -06:00
parent ee63647b0a
commit 9c4854adc5
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
2 changed files with 2538 additions and 0 deletions

2500
input/day2.txt 100644

File diff suppressed because it is too large Load Diff

38
src/day2.nu 100644
View File

@ -0,0 +1,38 @@
let input = (open ../input/day2.txt | lines)
let choices = ($input | each { |i| $i | split words })
def part1 [om, mm] {
let msel = (if $mm == 'X' { 1 } else { if $mm == 'Y' { 2 } else { 3 } })
let round = (
if $mm == 'X' {
if $om == 'A' { 3 } else { if $om == 'B' { 0 } else { 6 } }
} else {
if $mm == 'Y' {
if $om == 'A' { 6 } else { if $om == 'B' { 3 } else { 0 } }
} else {
if $om == 'A' { 0 } else { if $om == 'B' { 6 } else { 3 } }
}
}
)
$msel + $round
}
def part2 [om, mm] {
let round = (if $mm == 'X' { 0 } else { if $mm == 'Y' { 3 } else { 6 } })
let msel = (
if $om == 'A' {
if $mm == 'X' { 3 } else { if $mm == 'Y' { 1 } else { 2 } }
} else {
if $om == 'B' {
if $mm == 'X' { 1 } else { if $mm == 'Y' { 2 } else { 3 } }
} else {
if $mm == 'X' { 2 } else { if $mm == 'Y' { 3 } else { 1 } }
}
}
)
$msel + $round
}
$choices | each { |c| part1 $c.0 $c.1 } | math sum
$choices | each { |c| part2 $c.0 $c.1 } | math sum