chore(day17): log output
This commit is contained in:
parent
fd85530d88
commit
adc01f4df9
|
@ -8,7 +8,7 @@ import (
|
||||||
aoc "go.sour.is/advent-of-code"
|
aoc "go.sour.is/advent-of-code"
|
||||||
)
|
)
|
||||||
|
|
||||||
// var log = aoc.Log
|
var log = aoc.Log
|
||||||
|
|
||||||
func main() { aoc.MustResult(aoc.Runner(run)) }
|
func main() { aoc.MustResult(aoc.Runner(run)) }
|
||||||
|
|
||||||
|
@ -26,10 +26,14 @@ func run(scan *bufio.Scanner) (*result, error) {
|
||||||
text := scan.Text()
|
text := scan.Text()
|
||||||
m = append(m, []rune(text))
|
m = append(m, []rune(text))
|
||||||
}
|
}
|
||||||
|
log("start day 17")
|
||||||
|
|
||||||
result := result{}
|
result := result{}
|
||||||
result.valuePT1 = search(m, 1, 3)
|
result.valuePT1 = search(m, 1, 3)
|
||||||
|
log("result from part 1 = ", result.valuePT1)
|
||||||
|
|
||||||
result.valuePT2 = search(m, 4, 10)
|
result.valuePT2 = search(m, 4, 10)
|
||||||
|
log("result from part 2 = ", result.valuePT2)
|
||||||
|
|
||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
@ -157,7 +161,7 @@ func search(m Map, minSteps, maxSteps int8) int {
|
||||||
g := graph{min: minSteps, max: maxSteps, m: m, target: target}
|
g := graph{min: minSteps, max: maxSteps, m: m, target: target}
|
||||||
cost, path := aoc.FindPath[int16, position](&g, position{loc: start}, position{loc: target})
|
cost, path := aoc.FindPath[int16, position](&g, position{loc: start}, position{loc: target})
|
||||||
|
|
||||||
fmt.Println("total map reads = ", g.reads)
|
log("total map reads = ", g.reads)
|
||||||
printGraph(m, path)
|
printGraph(m, path)
|
||||||
|
|
||||||
return int(cost)
|
return int(cost)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) {
|
func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) {
|
||||||
|
@ -33,7 +34,10 @@ func MustResult[T any](result T, err error) {
|
||||||
Log("result", result)
|
Log("result", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Log(v ...any) { fmt.Fprintln(os.Stderr, v...) }
|
func Log(v ...any) {
|
||||||
|
fmt.Fprint(os.Stderr, time.Now(), ": ")
|
||||||
|
fmt.Fprintln(os.Stderr, v...)
|
||||||
|
}
|
||||||
func Logf(format string, v ...any) {
|
func Logf(format string, v ...any) {
|
||||||
if !strings.HasSuffix(format, "\n") {
|
if !strings.HasSuffix(format, "\n") {
|
||||||
format += "\n"
|
format += "\n"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user