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

View File

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

View File

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

View File

@@ -17,10 +17,10 @@ func ParseInput(filepath string) []string {
return strings.Split(string(content), "\n") return strings.Split(string(content), "\n")
} }
func PartOne(input []string) int { func PartOne(data []string) int {
maxCalories, currentElf := 0, 0 maxCalories, currentElf := 0, 0
for _, line := range input { for _, line := range data {
if line == "" { if line == "" {
maxCalories = max(maxCalories, currentElf) maxCalories = max(maxCalories, currentElf)
currentElf = 0 currentElf = 0
@@ -33,11 +33,11 @@ func PartOne(input []string) int {
return max(maxCalories, currentElf) return max(maxCalories, currentElf)
} }
func PartTwo(input []string) int { func PartTwo(data []string) int {
var totals []int var totals []int
currentElf := 0 currentElf := 0
for _, line := range input { for _, line := range data {
if line == "" { if line == "" {
totals = append(totals, currentElf) totals = append(totals, currentElf)
currentElf = 0 currentElf = 0