Compare commits
4 Commits
d8e7573204
...
bd8c2cca31
| Author | SHA1 | Date | |
|---|---|---|---|
| bd8c2cca31 | |||
| 4013ad8330 | |||
| a344eef0e3 | |||
| 824eb6d5a2 |
@@ -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"
|
||||
|
||||
32
internal/2015/DayOne/code.go
Normal file
32
internal/2015/DayOne/code.go
Normal 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
|
||||
}
|
||||
30
internal/2015/DayOne/code_test.go
Normal file
30
internal/2015/DayOne/code_test.go
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
1
internal/data/2015/DayOne/input.txt
Normal file
1
internal/data/2015/DayOne/input.txt
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user