summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2023-12-08 19:08:25 +0100
committerMartin Polden <mpolden@mpolden.no>2023-12-08 19:08:25 +0100
commit458d99c36b52c7217e45df2a51e9243c984fb028 (patch)
tree6c85da6c3f9a36110917fd8644a89fec414410ac
parent99658155bfbd214f126e9bc5f1aed691c12b199c (diff)
aoc23: add frequency
-rw-r--r--aoc23/util.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/aoc23/util.go b/aoc23/util.go
index 18ab3ec..414756a 100644
--- a/aoc23/util.go
+++ b/aoc23/util.go
@@ -138,10 +138,12 @@ func filter[V any](values []V, pred func(v V) bool) []V {
return filtered
}
-func anyMatch[V any](values []V, pred func(v V) bool) bool { return len(filter(values, pred)) > 0 }
+func frequency[V any](values []V, pred func(v V) bool) int { return len(filter(values, pred)) }
+
+func anyMatch[V any](values []V, pred func(v V) bool) bool { return frequency(values, pred) > 0 }
func allMatch[V any](values []V, pred func(v V) bool) bool {
- return len(filter(values, pred)) == len(values)
+ return frequency(values, pred) == len(values)
}
func noneMatch[V any](values []V, pred func(v V) bool) bool { return !anyMatch(values, pred) }