aboutsummaryrefslogtreecommitdiff
path: root/challenge-090
diff options
context:
space:
mode:
authorAdam Russell <ac.russell@live.com>2020-12-23 20:42:30 -0500
committerAdam Russell <ac.russell@live.com>2020-12-23 20:42:30 -0500
commit3b5e7bf0c701bd9fc227b6ad6924efeacbfca0f8 (patch)
treeaa6dc6686164db9af275bea97b5734fd48262c17 /challenge-090
parent9574d750f4be19fd25966be9ad881e14b8d8174c (diff)
downloadperlweeklychallenge-club-3b5e7bf0c701bd9fc227b6ad6924efeacbfca0f8.tar.gz
perlweeklychallenge-club-3b5e7bf0c701bd9fc227b6ad6924efeacbfca0f8.tar.bz2
perlweeklychallenge-club-3b5e7bf0c701bd9fc227b6ad6924efeacbfca0f8.zip
added Prolog solutions
Diffstat (limited to 'challenge-090')
-rw-r--r--challenge-090/adam-russell/blog1.txt1
-rwxr-xr-xchallenge-090/adam-russell/prolog/ch-1bin0 -> 995472 bytes
-rw-r--r--challenge-090/adam-russell/prolog/ch-1.p38
-rwxr-xr-xchallenge-090/adam-russell/prolog/ch-2bin0 -> 993700 bytes
-rw-r--r--challenge-090/adam-russell/prolog/ch-2.p32
5 files changed, 71 insertions, 0 deletions
diff --git a/challenge-090/adam-russell/blog1.txt b/challenge-090/adam-russell/blog1.txt
new file mode 100644
index 0000000000..57006d0158
--- /dev/null
+++ b/challenge-090/adam-russell/blog1.txt
@@ -0,0 +1 @@
+www.rabbitfarm.com/cgi-bin/blosxom/prolog/2020/12/13
diff --git a/challenge-090/adam-russell/prolog/ch-1 b/challenge-090/adam-russell/prolog/ch-1
new file mode 100755
index 0000000000..2a2e015671
--- /dev/null
+++ b/challenge-090/adam-russell/prolog/ch-1
Binary files differ
diff --git a/challenge-090/adam-russell/prolog/ch-1.p b/challenge-090/adam-russell/prolog/ch-1.p
new file mode 100644
index 0000000000..ef0313b5be
--- /dev/null
+++ b/challenge-090/adam-russell/prolog/ch-1.p
@@ -0,0 +1,38 @@
+/*
+* Write a script to print nucleiobase count in the given DNA sequence.
+* Also, print the complementary sequence where Thymine (T) on one strand
+* is always facing an adenine (A) and vice versa; guanine (G) is always
+* facing a cytosine (C) and vice versa.
+*/
+
+:- initialization(main).
+
+nucleotide_pair('A', 'T').
+nucleotide_pair('C', 'G').
+
+compliment([H|T], [Compliment|RestOfCompliment]):-
+ var(Compliment),
+ atom_chars(A, [H]),
+ (nucleotide_pair(A, X); nucleotide_pair(X, A)),
+ atom_chars(X, [Compliment]),
+ compliment(T, RestOfCompliment).
+compliment([H|T], [Compliment|RestOfCompliment]):-
+ (nucleotide_pair(A, Compliment); nucleotide_pair(Compliment, A)),
+ atom_chars(A, [H]),
+ compliment(T, RestOfCompliment).
+compliment([], _).
+compliment(_, []).
+
+main:-
+ Sequence = 'GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG',
+ atom_chars(Sequence, SequenceChars),
+ length(SequenceChars, SequenceLength),
+ format("Sequence length is ~d.~n", [SequenceLength]),
+ length(Compliment, SequenceLength),
+ compliment(SequenceChars, Compliment),
+ atom_chars(ACompliment, Compliment),
+ compliment(OriginalSequence, Compliment),
+ atom_chars(AOriginalSequence, OriginalSequence),
+ format("Original sequence is ~a.~n", [AOriginalSequence]),
+ format("Complimentary sequence is ~a.~n", [ACompliment]),
+ halt.
diff --git a/challenge-090/adam-russell/prolog/ch-2 b/challenge-090/adam-russell/prolog/ch-2
new file mode 100755
index 0000000000..39004fbbda
--- /dev/null
+++ b/challenge-090/adam-russell/prolog/ch-2
Binary files differ
diff --git a/challenge-090/adam-russell/prolog/ch-2.p b/challenge-090/adam-russell/prolog/ch-2.p
new file mode 100644
index 0000000000..cf0ceb67d2
--- /dev/null
+++ b/challenge-090/adam-russell/prolog/ch-2.p
@@ -0,0 +1,32 @@
+/*
+* You are given two positive numbers A and B.
+* Write a script to demonstrate Ethiopian Multiplication
+* using the given numberss
+*/
+
+:- initialization(main).
+
+ethiopean_multiplication(Operands, Product):-
+ ethiopean_multiplication(Operands, [], Product).
+ethiopean_multiplication([1, _], IntermediateTerms, Product):-
+ sum_list(IntermediateTerms, Product).
+ethiopean_multiplication(Operands, IntermediateTerms, Product):-
+ [A0, B0] = Operands,
+ A is A0 div 2,
+ B is B0 * 2,
+ M is A mod 2,
+ M == 1,
+ ethiopean_multiplication([A, B], [B|IntermediateTerms], Product).
+ethiopean_multiplication(Operands, IntermediateTerms, Product):-
+ [A0, B0] = Operands,
+ A is A0 div 2,
+ B is B0 * 2,
+ M is A mod 2,
+ M == 0,
+ ethiopean_multiplication([A, B], IntermediateTerms, Product).
+
+main:-
+ [A, B] = [14, 12],
+ ethiopean_multiplication([A, B], Product),
+ format("Product of ~d x ~d (via Ethiopean Multiplication) is ~d.~n", [A, B, Product]),
+ halt.