Compare commits

...

4 Commits

Author SHA1 Message Date
8ad1b166f3 feat: add both solutions 2025-11-29 16:07:02 +01:00
1f3b42b266 feat: 2015D5 dataset 2025-11-29 16:06:54 +01:00
9521677ca8 test: add unit tests for both parts 2025-11-29 16:06:42 +01:00
8938992384 feat: include 2015D5 2025-11-29 16:06:34 +01:00
4 changed files with 1110 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,77 @@
package dayfive
import (
"advent-of-code/internal/registry"
"os"
"strings"
)
func init() {
registry.Register("2015D5", ParseInput, PartOne, PartTwo)
}
func ParseInput(filepath string) []string {
content, _ := os.ReadFile(filepath)
return strings.Split(string(content), "\n")
}
func PartOne(data []string) int {
count := 0
for _, line := range data {
vowelCount := strings.Count(line, "a") + strings.Count(line, "e") + strings.Count(line, "i") + strings.Count(line, "o") + strings.Count(line, "u")
if vowelCount < 3 {
continue
}
hasDoubleLetter := false
for i := 1; i < len(line); i++ {
if line[i] == line[i-1] {
hasDoubleLetter = true
break
}
}
if !hasDoubleLetter {
continue
}
if strings.Contains(line, "ab") || strings.Contains(line, "cd") || strings.Contains(line, "pq") || strings.Contains(line, "xy") {
continue
}
count++
}
return count
}
func PartTwo(data []string) int {
count := 0
for _, line := range data {
if len(line) < 4 {
continue
}
hasNonOverlappingPair := false
for i := 0; i < len(line)-1; i++ {
pair := line[i : i+2]
if strings.Contains(line[i+2:], pair) {
hasNonOverlappingPair = true
break
}
}
if !hasNonOverlappingPair {
continue
}
hasRepeatingLetterWithGap := false
for i := 0; i < len(line)-2; i++ {
if line[i] == line[i+2] {
hasRepeatingLetterWithGap = true
break
}
}
if hasRepeatingLetterWithGap {
count++
}
}
return count
}

View File

@@ -0,0 +1,32 @@
package dayfive
import "testing"
func TestPartOne(t *testing.T) {
input := []string{
"ugknbfddgicrmopn",
"aaa",
"jchzalrnumimnmhp",
"haegwjzuvuyypxyu",
"dvszwmarrgswjxmb",
}
expected := 2
got := PartOne(input)
if got != expected {
t.Errorf("PartOne() = %d, want %d", got, expected)
}
}
func TestPartTwo(t *testing.T) {
input := []string{
"qjhvhtzxzqqjkmpb",
"xxyxx",
"uurcxstgmygtbstg",
"ieodomkazucvgmuy",
}
expected := 2
got := PartTwo(input)
if got != expected {
t.Errorf("PartTwo() = %d, want %d", got, expected)
}
}

File diff suppressed because it is too large Load Diff