Compare commits
4 Commits
0949840317
...
11b6227d0e
| Author | SHA1 | Date | |
|---|---|---|---|
| 11b6227d0e | |||
| 31660c7510 | |||
| 728bbb2a06 | |||
| 16a99ba8d8 |
@@ -32,7 +32,10 @@ import (
|
|||||||
_ "advent-of-code/internal/2021/DayOne"
|
_ "advent-of-code/internal/2021/DayOne"
|
||||||
_ "advent-of-code/internal/2021/DayThree"
|
_ "advent-of-code/internal/2021/DayThree"
|
||||||
_ "advent-of-code/internal/2021/DayTwo"
|
_ "advent-of-code/internal/2021/DayTwo"
|
||||||
|
|
||||||
|
// 2022
|
||||||
_ "advent-of-code/internal/2022/DayOne"
|
_ "advent-of-code/internal/2022/DayOne"
|
||||||
|
_ "advent-of-code/internal/2022/DayTwo"
|
||||||
|
|
||||||
// 2025
|
// 2025
|
||||||
_ "advent-of-code/internal/2025/DayOne"
|
_ "advent-of-code/internal/2025/DayOne"
|
||||||
|
|||||||
42
internal/2022/DayTwo/code.go
Normal file
42
internal/2022/DayTwo/code.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package daytwo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"advent-of-code/internal/registry"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registry.Register("2022D2", ParseInput, PartOne, PartTwo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseInput(filepath string) []string {
|
||||||
|
content, _ := os.ReadFile(filepath)
|
||||||
|
return strings.Split(strings.Trim(string(content), "\n"), "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func PartOne(data []string) int {
|
||||||
|
totalScore := 0
|
||||||
|
for _, line := range data {
|
||||||
|
opponent := line[0]
|
||||||
|
me := line[2]
|
||||||
|
|
||||||
|
shapeScore := int(me - 'X' + 1)
|
||||||
|
|
||||||
|
var outcomeScore int
|
||||||
|
if (opponent == 'A' && me == 'Y') || (opponent == 'B' && me == 'Z') || (opponent == 'C' && me == 'X') {
|
||||||
|
outcomeScore = 6
|
||||||
|
} else if (opponent == 'A' && me == 'X') || (opponent == 'B' && me == 'Y') || (opponent == 'C' && me == 'Z') {
|
||||||
|
outcomeScore = 3
|
||||||
|
} else {
|
||||||
|
outcomeScore = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
totalScore += shapeScore + outcomeScore
|
||||||
|
}
|
||||||
|
return totalScore
|
||||||
|
}
|
||||||
|
|
||||||
|
func PartTwo(data []string) int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
17
internal/2022/DayTwo/code_test.go
Normal file
17
internal/2022/DayTwo/code_test.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package daytwo
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
var testInput = []string{
|
||||||
|
"A Y",
|
||||||
|
"B X",
|
||||||
|
"C Z",
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPartOne(t *testing.T) {
|
||||||
|
expected := 15
|
||||||
|
got := PartOne(testInput)
|
||||||
|
if got != expected {
|
||||||
|
t.Errorf("PartOne() = %d, want %d", got, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
2500
internal/data/2022/DayTwo/input.txt
Normal file
2500
internal/data/2022/DayTwo/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user