aboutsummaryrefslogtreecommitdiff
path: root/challenge-276
diff options
context:
space:
mode:
author2colours <polgar.marton@windowslive.com>2024-07-06 15:45:50 +0200
committer2colours <polgar.marton@windowslive.com>2024-07-06 15:45:50 +0200
commit740d8c5b91ceceeee5ffc2410378fd1c5e1427a2 (patch)
tree1218384bc5f53de426d7953cd6c49c12e40e20be /challenge-276
parentd3cd6c8a7072e6f3566176284074c04501bfe8e3 (diff)
downloadperlweeklychallenge-club-740d8c5b91ceceeee5ffc2410378fd1c5e1427a2.tar.gz
perlweeklychallenge-club-740d8c5b91ceceeee5ffc2410378fd1c5e1427a2.tar.bz2
perlweeklychallenge-club-740d8c5b91ceceeee5ffc2410378fd1c5e1427a2.zip
Add remaining Prolog solutions for week 275 and 276
Diffstat (limited to 'challenge-276')
-rw-r--r--challenge-276/2colours/prolog/ch-1.p2
-rw-r--r--challenge-276/2colours/prolog/ch-2.p8
2 files changed, 10 insertions, 0 deletions
diff --git a/challenge-276/2colours/prolog/ch-1.p b/challenge-276/2colours/prolog/ch-1.p
new file mode 100644
index 0000000000..b952b23d49
--- /dev/null
+++ b/challenge-276/2colours/prolog/ch-1.p
@@ -0,0 +1,2 @@
+:- use_module(library(clpfd)).
+task1(Hours, Nr_Complete_Day_Pairs) :- findall([V, W], (nth0(I, Hours, V), J #> I, nth0(J, Hours, W), (V - W) mod 24 =:= 0), Res), length(Res, Nr_Complete_Day_Pairs).
diff --git a/challenge-276/2colours/prolog/ch-2.p b/challenge-276/2colours/prolog/ch-2.p
new file mode 100644
index 0000000000..259640b286
--- /dev/null
+++ b/challenge-276/2colours/prolog/ch-2.p
@@ -0,0 +1,8 @@
+aggregate_bag(Value-Amount, [], [Value-Amount]).
+aggregate_bag(Value-Amount, [Value-Old_Amount|Rest], [Value-New_Amount|Rest]) :- !, New_Amount is Old_Amount + Amount.
+aggregate_bag(Value-Amount, [Other_Value-Amount2|Rest], [Value-Amount, Other_Value-Amount2|Rest]).
+
+% task2(Ints, Most_Frequent_Count) :- clumped(Ints, Ints_RLE), msort(Ints_RLE, Sorted_RLE), foldl(aggregate_bag, Sorted_RLE, [], Aggregated_RLE), pairs_values(Aggregated_RLE, Counts), max_list(Counts, Max_Count), include(=(Max_Count), Counts, All_Maxes), sum_list(All_Maxes, Most_Frequent_Count).
+
+task2(Ints, Most_Frequent_Count) :- msort(Ints, Sorted_Ints), clumped(Sorted_Ints, Ints_Counted), pairs_values(Ints_Counted, Counts), max_list(Counts, Max_Count), include(=(Max_Count), Counts, All_Maxes), sum_list(All_Maxes, Most_Frequent_Count).
+