Compare commits
4 Commits
1f5b8247a9
...
301d93157c
| Author | SHA1 | Date | |
|---|---|---|---|
| 301d93157c | |||
| 7e0a1e71a7 | |||
| 962bc923f3 | |||
| 76568a801d |
@@ -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"
|
||||
|
||||
43
internal/2015/DayThree/code.go
Normal file
43
internal/2015/DayThree/code.go
Normal 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
|
||||
}
|
||||
24
internal/2015/DayThree/code_test.go
Normal file
24
internal/2015/DayThree/code_test.go
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
1
internal/data/2015/DayThree/input.txt
Normal file
1
internal/data/2015/DayThree/input.txt
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user