Compare commits

..

4 Commits

Author SHA1 Message Date
301d93157c feat: add part one solution 2025-11-28 17:51:51 +01:00
7e0a1e71a7 test: add unit test for p1 2025-11-28 17:51:10 +01:00
962bc923f3 feat: include 2015D3 2025-11-28 17:50:59 +01:00
76568a801d feat: add input for 2015D3 2025-11-28 17:50:29 +01:00
4 changed files with 69 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import (
"regexp"
_ "advent-of-code/internal/2015/DayOne"
_ "advent-of-code/internal/2015/DayThree"
_ "advent-of-code/internal/2015/DayTwo"
_ "advent-of-code/internal/2020/DayEight"
_ "advent-of-code/internal/2020/DayFour"

View File

@@ -0,0 +1,43 @@
package daythree
import (
"advent-of-code/internal/registry"
"os"
)
type coordinates struct {
x, y int
}
func init() {
registry.Register("2015D3", ParseInput, PartOne, PartTwo)
}
func ParseInput(filepath string) string {
content, _ := os.ReadFile(filepath)
return string(content)
}
func PartOne(data string) int {
houses := make(map[coordinates]int)
x, y := 0, 0
houses[coordinates{x, y}] = 1
for _, direction := range data {
switch direction {
case '>':
x++
case '<':
x--
case '^':
y++
case 'v':
y--
}
houses[coordinates{x, y}]++
}
return len(houses)
}
func PartTwo(data string) int {
return 0
}

View File

@@ -0,0 +1,24 @@
package daythree
import "testing"
func TestPartOne(t *testing.T) {
tests := []struct {
name string
input string
expected int
}{
{">", ">", 2},
{"^>v<", "^>v<", 4},
{"^v^v^v^v^v", "^v^v^v^v^v", 2},
}
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