mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-04-11 07:23:46 +01:00
Compare commits
2 Commits
cacbb11b7c
...
475ccfe0ba
Author | SHA1 | Date | |
---|---|---|---|
475ccfe0ba | |||
1ea679ebe3 |
@ -2,5 +2,14 @@ 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.001628 ns/op
|
BenchmarkMain-12 1000000000 0.001576 ns/op
|
||||||
ok github.com/onyx-and-iris/aoc2024/day-01 0.015s
|
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
|
||||||
|
@ -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]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ EXE := $(BIN_DIR)/$(program)
|
|||||||
|
|
||||||
.DEFAULT_GOAL := build
|
.DEFAULT_GOAL := build
|
||||||
|
|
||||||
.PHONY: fmt vet build clean
|
.PHONY: fmt vet build bench clean
|
||||||
fmt:
|
fmt:
|
||||||
$(GO) fmt ./...
|
$(GO) fmt ./...
|
||||||
|
|
||||||
@ -18,6 +18,9 @@ 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 $@
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ EXE := \$(BIN_DIR)/\$(program)
|
|||||||
|
|
||||||
.DEFAULT_GOAL := build
|
.DEFAULT_GOAL := build
|
||||||
|
|
||||||
.PHONY: fmt vet build clean
|
.PHONY: fmt vet build bench clean
|
||||||
fmt:
|
fmt:
|
||||||
\$(GO) fmt ./...
|
\$(GO) fmt ./...
|
||||||
|
|
||||||
@ -31,6 +31,9 @@ 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 \$@
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user