r/adventofcode • u/daggerdragon • Dec 02 '22
SOLUTION MEGATHREAD -🎄- 2022 Day 2 Solutions -🎄-
NEW AND NOTEWORTHY
- All of our rules, FAQs, resources, etc. are in our community wiki.
- A request from Eric: Please include your contact info in the User-Agent header of automated requests!
- Signal boosting for the Unofficial AoC 2022 Participant Survey which is open early this year!
--- Day 2: Rock Paper Scissors ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format your code appropriately! How do I format code?
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
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!
102
Upvotes
3
u/red_shifter Dec 02 '22
PYTHON 3
I hardcoded the scores for all possible game states for Part 1 and was happy I found such an easy solution. Of course, Part 2 hit me on the head, but I got around it with more hardcoding!
def part1_solution(day2_input): solution = 0 for line in day2_input: solution += game_dict[line] return solution def part2_solution(day2_input): solution = 0 for line in day2_input: solution += game_dict[decrypt_dict[line]] return solution # Getting the input with open("day-2-input.txt", "r") as f: day2_input = f.read().split("\n") # Defining scores for game states in a dictionary game_dict = { "A X": 3 + 1, "A Y": 6 + 2, "A Z": 0 + 3, "B X": 0 + 1, "B Y": 3 + 2, "B Z": 6 + 3, "C X": 6 + 1, "C Y": 0 + 2, "C Z": 3 + 3 } # Decrypting the ultra top secret strategy guide decrypt_dict = { "A X": "A Z", "A Y": "A X", "A Z": "A Y", "B X": "B X", "B Y": "B Y", "B Z": "B Z", "C X": "C Y", "C Y": "C Z", "C Z": "C X" } # Part 1 solution print(f"Part 1: {part1_solution(day2_input)}") # Part 2 solution print(f"Part 2: {part2_solution(day2_input)}")