mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 22:30:47 +00:00
remove occurrences var
This commit is contained in:
parent
cacbb11b7c
commit
1ea679ebe3
@ -32,27 +32,26 @@ func Solve() (int, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var occurrences int
|
for i, n := range right[indx:] {
|
||||||
for _, n := range right[indx:] {
|
|
||||||
if n > k {
|
if n > k {
|
||||||
|
similarity += k * v * i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
occurrences++
|
|
||||||
}
|
}
|
||||||
similarity += k * v * occurrences
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return similarity, nil
|
return similarity, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseLines(r io.Reader) (map[int]int, []int, error) {
|
func parseLines(r io.Reader) (map[int]int, []int, error) {
|
||||||
var left map[int]int = make(map[int]int)
|
left := make(map[int]int)
|
||||||
var right []int
|
right := []int{}
|
||||||
|
|
||||||
scanner := bufio.NewScanner(r)
|
scanner := bufio.NewScanner(r)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
nums := reNums.FindAllString(scanner.Text(), -1)
|
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]))
|
right = util.InsertSorted(right, util.MustConv(nums[1]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user