advent2022

Advent of Code 2022 Solutions
git clone git://bsandro.tech/advent2022
Log | Files | Refs | README | LICENSE

commit 548ffeebc310b42f89a6e137e2d125f19c5b5042
parent 385ca5828c4654c9a646ead3b2c967ad11445abf
Author: bsandro <email@bsandro.tech>
Date:   Fri,  2 Dec 2022 06:15:10 +0000

Day 02 part 2

Diffstat:
Mday02/main.go | 42++++++++++++++++++++++++++++--------------
1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/day02/main.go b/day02/main.go @@ -9,7 +9,7 @@ import ( func main() { if len(os.Args) > 1 { - day01(os.Args[1]) + day02(os.Args[1]) } else if len(os.Args) == 1 { fmt.Printf("usage: %s inputfile.txt\n", os.Args[0]) } else { @@ -17,7 +17,7 @@ func main() { } } -func day01(input_file string) { +func day02(input_file string) { fmt.Printf("day 02 input filename: %s\n", input_file) input, err := os.Open(input_file) if err != nil { @@ -26,23 +26,37 @@ func day01(input_file string) { defer input.Close() scanner := bufio.NewScanner(input) gameTable := map[string]int{ - "A X": 1+3, - "A Y": 2+6, - "A Z": 3+0, - "B X": 1+0, - "B Y": 2+3, - "B Z": 3+6, - "C X": 1+6, - "C Y": 2+0, - "C Z": 3+3, + "A X": 1 + 3, + "A Y": 2 + 6, + "A Z": 3 + 0, + "B X": 1 + 0, + "B Y": 2 + 3, + "B Z": 3 + 6, + "C X": 1 + 6, + "C Y": 2 + 0, + "C Z": 3 + 3, + } + riggedTable := map[string]int{ + "A X": 3 + 0, + "A Y": 1 + 3, + "A Z": 2 + 6, + "B X": 1 + 0, + "B Y": 2 + 3, + "B Z": 3 + 6, + "C X": 2 + 0, + "C Y": 3 + 3, + "C Z": 1 + 6, } - score := 0 + score1 := 0 + score2 := 0 for scanner.Scan() { - score += gameTable[scanner.Text()] + score1 += gameTable[scanner.Text()] + score2 += riggedTable[scanner.Text()] } if err = scanner.Err(); err != nil { log.Fatal(err) } - fmt.Printf("score: %d\n", score); + fmt.Printf("part 1 score: %d\n", score1) + fmt.Printf("part 2 score: %d\n", score2) }