Compare commits

..

4 Commits

Author SHA1 Message Date
bd8c2cca31 feat: add day1 part 1 solution 2025-11-28 16:28:15 +01:00
4013ad8330 feat: add d1 input 2025-11-28 16:28:01 +01:00
a344eef0e3 test: add unit test for p1 2025-11-28 16:27:55 +01:00
824eb6d5a2 feat: include 2015D1 2025-11-28 16:27:49 +01:00
4 changed files with 64 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import (
"path/filepath"
"regexp"
_ "advent-of-code/internal/2015/DayOne"
_ "advent-of-code/internal/2020/DayEight"
_ "advent-of-code/internal/2020/DayFour"
_ "advent-of-code/internal/2020/DayOne"

View File

@@ -0,0 +1,32 @@
package dayone
import (
"advent-of-code/internal/registry"
"os"
)
func init() {
registry.Register("2015D1", ParseInput, PartOne, PartTwo)
}
func ParseInput(filepath string) string {
content, _ := os.ReadFile(filepath)
return string(content)
}
func PartOne(data string) int {
floor := 0
for _, char := range data {
switch char {
case '(':
floor++
case ')':
floor--
}
}
return floor
}
func PartTwo(data string) int {
return 0
}

View File

@@ -0,0 +1,30 @@
package dayone
import "testing"
func TestPartOne(t *testing.T) {
tests := []struct {
name string
input string
expected int
}{
{"(())", "(())", 0},
{"()()", "()()", 0},
{"(((", "(((", 3},
{"(()(()(", "(()(()(", 3},
{"))(((((", "))(((((", 3},
{"())", "())", -1},
{"))(", "))(", -1},
{")))", ")))", -3},
{")())())", ")())())", -3},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := PartOne(tt.input)
if got != tt.expected {
t.Errorf("PartOne(%q) = %d, want %d", tt.input, got, tt.expected)
}
})
}
}

File diff suppressed because one or more lines are too long