refactor: standardize PartOne/PartTwo declarations

This commit is contained in:
2025-11-28 09:01:11 +01:00
parent 62969312e3
commit 3fb71d0cbf
4 changed files with 22 additions and 24 deletions

View File

@@ -39,9 +39,9 @@ func ParseInput(filepath string) []string {
return strings.Split(string(content), "\n")
}
func PartOne(input []string) int {
func PartOne(data []string) int {
maxSeatID := 0
for _, pass := range input {
for _, pass := range data {
seatID := calculateSeatID(pass)
if seatID > maxSeatID {
maxSeatID = seatID
@@ -50,12 +50,12 @@ func PartOne(input []string) int {
return maxSeatID
}
func PartTwo(input []string) int {
func PartTwo(data []string) int {
seatIDs := make(map[int]bool)
minSeatID := 1000
maxSeatID := 0
for _, pass := range input {
for _, pass := range data {
if len(pass) < 10 {
continue
}

View File

@@ -15,11 +15,11 @@ func ParseInput(filepath string) []string {
return strings.Split(strings.TrimSpace(string(content)), "\n")
}
func PartOne(input []string) int {
func PartOne(data []string) int {
total := 0
groupAnswers := make(map[rune]bool)
for idx, line := range input {
for idx, line := range data {
if line != "" {
for _, char := range line {
if char >= 'a' && char <= 'z' {
@@ -28,7 +28,7 @@ func PartOne(input []string) int {
}
}
if line == "" || idx == len(input)-1 {
if line == "" || idx == len(data)-1 {
total += len(groupAnswers)
groupAnswers = make(map[rune]bool)
}
@@ -39,12 +39,12 @@ func PartOne(input []string) int {
return total
}
func PartTwo(input []string) int {
func PartTwo(data []string) int {
total := 0
groupAnswers := make(map[rune]int)
groupSize := 0
for idx, line := range input {
for idx, line := range data {
if line != "" {
groupSize++
for _, char := range line {
@@ -54,7 +54,7 @@ func PartTwo(input []string) int {
}
}
if line == "" || idx == len(input)-1 {
if line == "" || idx == len(data)-1 {
for _, count := range groupAnswers {
if count == groupSize {
total++
@@ -67,4 +67,3 @@ func PartTwo(input []string) int {
return total
}

View File

@@ -15,14 +15,14 @@ func ParseInput(filepath string) []string {
return strings.Split(string(content), "\n")
}
func PartOne(input []string) int {
func PartOne(data []string) int {
trees := 0
column := 0
for row := range input {
if len(input[row]) == 0 {
for row := range data {
if len(data[row]) == 0 {
continue
}
if input[row][column%len(input[row])] == '#' {
if data[row][column%len(data[row])] == '#' {
trees++
}
column += 3
@@ -30,17 +30,17 @@ func PartOne(input []string) int {
return trees
}
func PartTwo(input []string) int {
func PartTwo(data []string) int {
result := 1
slopes := [][]int{{1, 1}, {3, 1}, {5, 1}, {7, 1}, {1, 2}}
for _, slope := range slopes {
trees := 0
column := 0
for row := 0; row < len(input); row += slope[1] {
if len(input[row]) == 0 {
for row := 0; row < len(data); row += slope[1] {
if len(data[row]) == 0 {
continue
}
if input[row][column%len(input[row])] == '#' {
if data[row][column%len(data[row])] == '#' {
trees++
}
column += slope[0]
@@ -49,4 +49,3 @@ func PartTwo(input []string) int {
}
return result
}