add filter function to filter zwires from wires

This commit is contained in:
onyx-and-iris 2024-12-26 13:12:13 +00:00
parent d244a9cc35
commit 4aaf594e23

View File

@ -13,7 +13,7 @@ const (
target 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) initial := make(map[string]int)
wires := make(map[string]int) wires := make(map[string]int)
expressions := []expression{} 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 { 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 { func mustConv(s string) int {
@ -82,3 +86,13 @@ func mustConvBinToDec(s string) int {
} }
return int(n) 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
}