mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 06:10:47 +00:00
add filter function to filter zwires from wires
This commit is contained in:
parent
d244a9cc35
commit
4aaf594e23
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user