From 3fb71d0cbf7c336bb99e7f7be1c7f14262f0da6a Mon Sep 17 00:00:00 2001 From: Kharec Date: Fri, 28 Nov 2025 09:01:11 +0100 Subject: [PATCH] refactor: standardize PartOne/PartTwo declarations --- internal/2020/DayFive/code.go | 8 ++++---- internal/2020/DaySix/code.go | 13 ++++++------- internal/2020/DayThree/code.go | 17 ++++++++--------- internal/2022/DayOne/code.go | 8 ++++---- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/internal/2020/DayFive/code.go b/internal/2020/DayFive/code.go index dce8086..2045476 100644 --- a/internal/2020/DayFive/code.go +++ b/internal/2020/DayFive/code.go @@ -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 } diff --git a/internal/2020/DaySix/code.go b/internal/2020/DaySix/code.go index fdc1249..edc87a6 100644 --- a/internal/2020/DaySix/code.go +++ b/internal/2020/DaySix/code.go @@ -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 } - diff --git a/internal/2020/DayThree/code.go b/internal/2020/DayThree/code.go index 53764ab..fc2638a 100644 --- a/internal/2020/DayThree/code.go +++ b/internal/2020/DayThree/code.go @@ -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 } - diff --git a/internal/2022/DayOne/code.go b/internal/2022/DayOne/code.go index b7bc4d3..37298ed 100644 --- a/internal/2022/DayOne/code.go +++ b/internal/2022/DayOne/code.go @@ -17,10 +17,10 @@ func ParseInput(filepath string) []string { return strings.Split(string(content), "\n") } -func PartOne(input []string) int { +func PartOne(data []string) int { maxCalories, currentElf := 0, 0 - for _, line := range input { + for _, line := range data { if line == "" { maxCalories = max(maxCalories, currentElf) currentElf = 0 @@ -33,11 +33,11 @@ func PartOne(input []string) int { return max(maxCalories, currentElf) } -func PartTwo(input []string) int { +func PartTwo(data []string) int { var totals []int currentElf := 0 - for _, line := range input { + for _, line := range data { if line == "" { totals = append(totals, currentElf) currentElf = 0