day two
This commit is contained in:
parent
deb4ec42ad
commit
6688ec09c3
@ -1,7 +0,0 @@
|
||||
array of 3 slots
|
||||
|
||||
always sorted low to high
|
||||
|
||||
loop through array, if lower than contents, replace with contesnts
|
||||
|
||||
keep doing this until the end
|
2500
2022/day-02/input
Normal file
2500
2022/day-02/input
Normal file
File diff suppressed because it is too large
Load Diff
@ -1 +1,115 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed *
|
||||
var input embed.FS
|
||||
|
||||
func part1() int {
|
||||
data, err := fs.ReadFile(input, "input")
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: failed to read input: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
score := 0
|
||||
|
||||
for _, game := range strings.Split(string(data), "\n") {
|
||||
if game == "" {continue}
|
||||
switch game{
|
||||
case "A X":
|
||||
score += 1
|
||||
score += 3
|
||||
case "A Y":
|
||||
score += 2
|
||||
score += 6
|
||||
case "A Z":
|
||||
score += 3
|
||||
score += 0
|
||||
case "B X":
|
||||
score += 1
|
||||
score += 0
|
||||
case "B Y":
|
||||
score += 2
|
||||
score += 3
|
||||
case "B Z":
|
||||
score += 3
|
||||
score += 6
|
||||
case "C X":
|
||||
score += 1
|
||||
score += 6
|
||||
case "C Y":
|
||||
score += 2
|
||||
score += 0
|
||||
case "C Z":
|
||||
score += 3
|
||||
score += 3
|
||||
}
|
||||
}
|
||||
return score
|
||||
}
|
||||
|
||||
func part2() int {
|
||||
data, err := fs.ReadFile(input, "input")
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: failed to read input: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
score := 0
|
||||
|
||||
for _, game := range strings.Split(string(data), "\n") {
|
||||
if game == "" {continue}
|
||||
switch game{
|
||||
// rock
|
||||
case "A X":
|
||||
score += 0
|
||||
score += 3
|
||||
case "A Y":
|
||||
score += 3
|
||||
score += 1
|
||||
case "A Z":
|
||||
score += 6
|
||||
score += 2
|
||||
|
||||
// paper
|
||||
case "B X":
|
||||
score += 0
|
||||
score += 1
|
||||
case "B Y":
|
||||
score += 3
|
||||
score += 2
|
||||
case "B Z":
|
||||
score += 6
|
||||
score += 3
|
||||
|
||||
// scissors
|
||||
case "C X":
|
||||
score += 0
|
||||
score += 2
|
||||
case "C Y":
|
||||
score += 3
|
||||
score += 3
|
||||
case "C Z":
|
||||
score += 6
|
||||
score += 1
|
||||
}
|
||||
}
|
||||
return score
|
||||
}
|
||||
|
||||
func main() {
|
||||
scoreOne := part1()
|
||||
scoreTwo := part2()
|
||||
|
||||
fmt.Printf("The score on game one is %d\n", scoreOne)
|
||||
fmt.Printf("The score on game two is %d\n", scoreTwo)
|
||||
}
|
||||
|
3
2022/day-02/test_input
Normal file
3
2022/day-02/test_input
Normal file
@ -0,0 +1,3 @@
|
||||
A Y
|
||||
B X
|
||||
C Z
|
Loading…
x
Reference in New Issue
Block a user