From 4aaf594e23e90c2412ccfe6009d857c7afbf5c83 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 26 Dec 2024 13:12:13 +0000 Subject: [PATCH] add filter function to filter zwires from wires --- day-24/internal/one/util.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/day-24/internal/one/util.go b/day-24/internal/one/util.go index c96d3e7..ddc4ab4 100644 --- a/day-24/internal/one/util.go +++ b/day-24/internal/one/util.go @@ -13,7 +13,7 @@ const ( target ) -func parseLines(r io.Reader) (map[string]int, map[string]int, []expression, error) { +func parseLines(r io.Reader) (map[string]int, []expression, error) { initial := make(map[string]int) wires := make(map[string]int) expressions := []expression{} @@ -52,10 +52,14 @@ func parseLines(r io.Reader) (map[string]int, map[string]int, []expression, erro } if err := scanner.Err(); err != nil { - return nil, nil, nil, err + return nil, nil, err } - return initial, wires, expressions, nil + for k, v := range initial { + wires[k] = v + } + + return wires, expressions, nil } func mustConv(s string) int { @@ -82,3 +86,13 @@ func mustConvBinToDec(s string) int { } return int(n) } + +func filter(wires map[string]int, fn func(string) bool) []zWire { + var filtered []zWire + for name, value := range wires { + if fn(name) { + filtered = append(filtered, zWire{name, value}) + } + } + return filtered +}