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

1

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

Golang - mapped out the results, which made it easy to do the sums & get the results.


import (
    "fmt"
    "os"
    "time"

    "github.com/Galzzly/AoC/utils"
)

var results = map[string][]int{
    "A X": {4, 3},
    "A Y": {8, 4},
    "A Z": {3, 8},
    "B X": {1, 1},
    "B Y": {5, 5},
    "B Z": {9, 9},
    "C X": {7, 2},
    "C Y": {2, 6},
    "C Z": {6, 7},
}

func main() {
    start := time.Now()
    f := os.Args[1]
    lines := utils.ReadFileLineByLine(f)

    r1, r2 := game(lines)
    fmt.Println("Part 1:", r1)
    fmt.Println("Part 2:", r2)

    fmt.Println("Total Time:", time.Since(start))
}

func game(lines []string) (r1, r2 int) {
    for _, l := range lines {
        r1 += results[l][0]
        r2 += results[l][1]
    }
    return
}

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.