Compare commits

..

4 Commits

Author SHA1 Message Date
11b6227d0e feat: add P1 solution 2025-12-01 12:19:01 +01:00
31660c7510 test: add P1 unit test 2025-12-01 12:18:54 +01:00
728bbb2a06 feat: add input for 2022D2 2025-12-01 12:18:42 +01:00
16a99ba8d8 feat: include 2022D2 2025-12-01 12:18:36 +01:00
4 changed files with 2562 additions and 0 deletions

View File

@@ -32,7 +32,10 @@ import (
_ "advent-of-code/internal/2021/DayOne"
_ "advent-of-code/internal/2021/DayThree"
_ "advent-of-code/internal/2021/DayTwo"
// 2022
_ "advent-of-code/internal/2022/DayOne"
_ "advent-of-code/internal/2022/DayTwo"
// 2025
_ "advent-of-code/internal/2025/DayOne"

View 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
}

View 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)
}
}

File diff suppressed because it is too large Load Diff