From 458d99c36b52c7217e45df2a51e9243c984fb028 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Fri, 8 Dec 2023 19:08:25 +0100 Subject: aoc23: add frequency --- aoc23/util.go | 6 ++++-- 1 file 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) } -- cgit v1.2.3