r/adventofcode • • Dec 02 '22

SOLUTION MEGATHREAD -🎄- 2022 Day 2 Solutions -🎄-

NEW AND NOTEWORTHY


--- Day 2: Rock Paper Scissors ---


Post your code solution in this megathread.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:06:16, megathread unlocked!

103 Upvotes

1.5k comments sorted by

View all comments

2

u/antoniotto Dec 02 '22 edited Dec 05 '22

Ruby

input = File.readlines('inputs/day02.txt', chomp: true)

scores = { 'A X' => 4, 'A Y' => 8, 'A Z' => 3,  'B X' => 1, 'B Y' => 5, 'B Z' => 9,  'C X' => 7, 'C Y' => 2, 'C Z' => 6 }

solution1 = input.map(&scores).sum

scores2 = { 'A X' => 3, 'A Y' => 4, 'A Z' => 8, 'B X' => 1, 'B Y' => 5, 'B Z' => 9, 'C X' => 2, 'C Y' => 6, 'C Z' => 7 }

solution2 = input.map(&scores2).sum

puts solution1, solution2

2

u/radiales Dec 02 '22

That's genius

1

u/antoniotto Dec 02 '22

Too kind of you. I am just a beginner. 😊

1

u/daggerdragon Dec 05 '22

Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read on old.reddit and mobile apps.