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/farondis Dec 02 '22

my solution in go/golang, dict and list all options, yeah


func main() {
	dict := map[string]int{
		"A X": 1 + 3,
		"A Y": 2 + 6,
		"A Z": 3,
		"B X": 1,
		"B Y": 2 + 3,
		"B Z": 3 + 6,
		"C X": 1 + 6,
		"C Y": 2,
		"C Z": 3 + 3,
	}
	dict2 := map[string]int{
		"A X": 3,
		"A Y": 1 + 3,
		"A Z": 2 + 6,
		"B X": 1,
		"B Y": 2 + 3,
		"B Z": 3 + 6,
		"C X": 2,
		"C Y": 3 + 3,
		"C Z": 1 + 6,
	}

	input, err := os.ReadFile("input.txt")
	if err != nil {
		log.Fatal(err)
	}

	games, score1, score2 := strings.Split(string(input), "\n"), 0, 0
	for i := range games {
		value_part1, _ := dict[games[i]]
		value_part2, _ := dict2[games[i]]
		score1 += value_part1
		score2 += value_part2
	}
	fmt.Println(fmt.Sprint(score1))
	fmt.Println(fmt.Sprint(score2))

}

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.