Compare commits

..

No commits in common. "475ccfe0ba71894b4962ea8fa465773ae7e78e8a" and "cacbb11b7cb9523f447a78382b8751f5885c8001" have entirely different histories.

4 changed files with 11 additions and 25 deletions

View File

@ -2,14 +2,5 @@ goos: linux
goarch: amd64
pkg: github.com/onyx-and-iris/aoc2024/day-01
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
BenchmarkMain-12 1000000000 0.001576 ns/op
BenchmarkMain-12 1000000000 0.001731 ns/op
BenchmarkMain-12 1000000000 0.001616 ns/op
BenchmarkMain-12 1000000000 0.001597 ns/op
BenchmarkMain-12 1000000000 0.001559 ns/op
BenchmarkMain-12 1000000000 0.001657 ns/op
BenchmarkMain-12 1000000000 0.001542 ns/op
BenchmarkMain-12 1000000000 0.001561 ns/op
BenchmarkMain-12 1000000000 0.001574 ns/op
BenchmarkMain-12 1000000000 0.001582 ns/op
ok github.com/onyx-and-iris/aoc2024/day-01 0.126s
BenchmarkMain-12 1000000000 0.001628 ns/op
ok github.com/onyx-and-iris/aoc2024/day-01 0.015s

View File

@ -32,26 +32,27 @@ func Solve() (int, error) {
continue
}
for i, n := range right[indx:] {
var occurrences int
for _, 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) {
left := make(map[int]int)
right := []int{}
var left map[int]int = make(map[int]int)
var 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])] = left[util.MustConv(nums[0])] + 1
right = util.InsertSorted(right, util.MustConv(nums[1]))
}

View File

@ -8,7 +8,7 @@ EXE := $(BIN_DIR)/$(program)
.DEFAULT_GOAL := build
.PHONY: fmt vet build bench clean
.PHONY: fmt vet build clean
fmt:
$(GO) fmt ./...
@ -18,9 +18,6 @@ vet: fmt
build: vet | $(BIN_DIR)
$(GO) build -o $(EXE) .
bench:
$(GO) test . -test.count=10 -bench=. > benchmark
$(BIN_DIR):
@mkdir -p $@

View File

@ -21,7 +21,7 @@ EXE := \$(BIN_DIR)/\$(program)
.DEFAULT_GOAL := build
.PHONY: fmt vet build bench clean
.PHONY: fmt vet build clean
fmt:
\$(GO) fmt ./...
@ -31,9 +31,6 @@ vet: fmt
build: vet | \$(BIN_DIR)
\$(GO) build -o \$(EXE) ./\$(SRC_DIR)
bench:
\$(GO) test . -test.count=10 -bench=. > benchmark
\$(BIN_DIR):
@mkdir -p \$@