From 27a56dc7cdd8ead5a7f93f69a928f8376f864ec1 Mon Sep 17 00:00:00 2001 From: Kharec Date: Fri, 28 Nov 2025 15:26:23 +0100 Subject: [PATCH] refactor: create a execute() function to reuse in part two --- internal/2020/DayEight/code.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/2020/DayEight/code.go b/internal/2020/DayEight/code.go index d9261e5..6d01bff 100644 --- a/internal/2020/DayEight/code.go +++ b/internal/2020/DayEight/code.go @@ -35,15 +35,14 @@ func parseInstructions(data []string) []instruction { return instructions } -func PartOne(data []string) int { - instructions := parseInstructions(data) +func execute(instructions []instruction) (accumulator int, terminatedNormally bool) { visited := make(map[int]bool) - accumulator := 0 + accumulator = 0 pc := 0 for pc < len(instructions) { if visited[pc] { - return accumulator + return accumulator, false } visited[pc] = true @@ -59,6 +58,12 @@ func PartOne(data []string) int { } } + return accumulator, true +} + +func PartOne(data []string) int { + instructions := parseInstructions(data) + accumulator, _ := execute(instructions) return accumulator }