aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-04-28 04:10:08 +0100
committerGitHub <noreply@github.com>2025-04-28 04:10:08 +0100
commitafedfa75bb34545adc9781898d6f48b7a67d2da0 (patch)
treeec22256204aa12d73501d82ac742a88f46578fe8
parentf43cac465538de4bb0a6a526ecc91715611dfb83 (diff)
parent840b5dd297556125f499a1b12e373017ef5b59f0 (diff)
downloadperlweeklychallenge-club-afedfa75bb34545adc9781898d6f48b7a67d2da0.tar.gz
perlweeklychallenge-club-afedfa75bb34545adc9781898d6f48b7a67d2da0.tar.bz2
perlweeklychallenge-club-afedfa75bb34545adc9781898d6f48b7a67d2da0.zip
Merge pull request #11939 from adamcrussell/challenge-318
initial commit of Prolog solutions
-rw-r--r--challenge-318/adam-russell/blog1.txt1
-rw-r--r--challenge-318/adam-russell/prolog/ch-1.p21
-rw-r--r--challenge-318/adam-russell/prolog/ch-2.p56
3 files changed, 78 insertions, 0 deletions
diff --git a/challenge-318/adam-russell/blog1.txt b/challenge-318/adam-russell/blog1.txt
new file mode 100644
index 0000000000..0f80551133
--- /dev/null
+++ b/challenge-318/adam-russell/blog1.txt
@@ -0,0 +1 @@
+http://rabbitfarm.com/cgi-bin/blosxom/prolog/2025/04/27
diff --git a/challenge-318/adam-russell/prolog/ch-1.p b/challenge-318/adam-russell/prolog/ch-1.p
new file mode 100644
index 0000000000..2584a2dceb
--- /dev/null
+++ b/challenge-318/adam-russell/prolog/ch-1.p
@@ -0,0 +1,21 @@
+
+
+ group(Letters, Letter, Group):-
+ length(Letters, LengthLetters),
+ delete(Letters, Letter, Deleted),
+ length(Deleted, LengthDeleted),
+ Difference is LengthLetters - LengthDeleted,
+ Difference >= 3,
+ length(G1, Difference),
+ maplist(=(Letter), G1),
+ append(G1, _, G2),
+ append(_, G2, Letters),
+ atom_codes(Group, G1).
+ group(_, _, nil).
+
+
+ groupings(Word, Groupings):-
+ sort(Word, UniqueLetters),
+ maplist(group(Word), UniqueLetters, Groups),
+ delete(Groups, nil, Groupings).
+
diff --git a/challenge-318/adam-russell/prolog/ch-2.p b/challenge-318/adam-russell/prolog/ch-2.p
new file mode 100644
index 0000000000..58d9e91127
--- /dev/null
+++ b/challenge-318/adam-russell/prolog/ch-2.p
@@ -0,0 +1,56 @@
+
+
+ reverse_equals(List1, List2):-
+
+ subtract(List1, List2, []),
+
+
+ length(List1, Length),
+ findall(I, (
+ between(1, Length, I),
+ nth(I, List1, C1),
+ nth(I, List2, C2),
+ \+ C1 = C2
+ ), DifferenceIndices),
+
+
+ length(DifferenceIndices, NumberDifferences),
+ NumberDifferences > 0,
+ nth(1, DifferenceIndices, FirstIndex),
+ last(DifferenceIndices, LastIndex),
+ findall(E, (
+ between(FirstIndex, LastIndex, I),
+ nth(I, List1, E)
+ ), SubList1),
+ findall(E, (
+ between(FirstIndex, LastIndex, I),
+ nth(I, List2, E)
+ ), SubList2),
+
+
+ reverse(SubList1, Reverse1),
+ reverse(SubList2, Reverse2),
+ append(SubList1, Suffix1, S1),
+ append(SubList2, Suffix2, S2),
+ append(Reverse1, Suffix1, S3),
+ append(Reverse2, Suffix2, S4),
+ append(Prefix1, S1, List1),
+ append(Prefix2, S2, List2),
+ (append(Prefix1, S3, List2); append(Prefix2, S4, List1))
+.
+ reverse_equals(List1, List2):-
+
+ subtract(List1, List2, []),
+
+
+ length(List1, Length),
+ findall(I, (
+ between(1, Length, I),
+ nth(I, List1, C1),
+ nth(I, List2, C2),
+ \+ C1 = C2
+ ), DifferenceIndices),
+
+ length(DifferenceIndices, NumberDifferences),
+ NumberDifferences = 0.
+