From 1ea679ebe3edcf659e3bc154154500adba8ce827 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 1 Dec 2024 21:14:02 +0000 Subject: [PATCH] remove occurrences var --- day-01/internal/two/solve.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/day-01/internal/two/solve.go b/day-01/internal/two/solve.go index 405aad3..357b0d6 100644 --- a/day-01/internal/two/solve.go +++ b/day-01/internal/two/solve.go @@ -32,27 +32,26 @@ func Solve() (int, error) { continue } - var occurrences int - for _, n := range right[indx:] { + for i, n := range right[indx:] { if n > k { + similarity += k * v * i break } - occurrences++ } - similarity += k * v * occurrences } return similarity, nil } func parseLines(r io.Reader) (map[int]int, []int, error) { - var left map[int]int = make(map[int]int) - var right []int + left := make(map[int]int) + right := []int{} scanner := bufio.NewScanner(r) for scanner.Scan() { nums := reNums.FindAllString(scanner.Text(), -1) - left[util.MustConv(nums[0])] = left[util.MustConv(nums[0])] + 1 + + left[util.MustConv(nums[0])]++ right = util.InsertSorted(right, util.MustConv(nums[1])) }