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 goarch: amd64
pkg: github.com/onyx-and-iris/aoc2024/day-01 pkg: github.com/onyx-and-iris/aoc2024/day-01
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
BenchmarkMain-12 1000000000 0.001576 ns/op BenchmarkMain-12 1000000000 0.001628 ns/op
BenchmarkMain-12 1000000000 0.001731 ns/op ok github.com/onyx-and-iris/aoc2024/day-01 0.015s
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

View File

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

View File

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

View File

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