aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-193/adam-russell/blog.txt1
-rw-r--r--challenge-193/adam-russell/blog1.txt1
-rw-r--r--challenge-193/adam-russell/perl/ch-1.pl18
-rw-r--r--challenge-193/adam-russell/perl/ch-2.pl38
-rw-r--r--challenge-193/adam-russell/prolog/ch-1.p11
-rw-r--r--challenge-193/adam-russell/prolog/ch-2.p16
6 files changed, 85 insertions, 0 deletions
diff --git a/challenge-193/adam-russell/blog.txt b/challenge-193/adam-russell/blog.txt
new file mode 100644
index 0000000000..55569be593
--- /dev/null
+++ b/challenge-193/adam-russell/blog.txt
@@ -0,0 +1 @@
+http://www.rabbitfarm.com/cgi-bin/blosxom/perl/2022/12/03 \ No newline at end of file
diff --git a/challenge-193/adam-russell/blog1.txt b/challenge-193/adam-russell/blog1.txt
new file mode 100644
index 0000000000..2995501983
--- /dev/null
+++ b/challenge-193/adam-russell/blog1.txt
@@ -0,0 +1 @@
+http://www.rabbitfarm.com/cgi-bin/blosxom/prolog/2022/12/03 \ No newline at end of file
diff --git a/challenge-193/adam-russell/perl/ch-1.pl b/challenge-193/adam-russell/perl/ch-1.pl
new file mode 100644
index 0000000000..8ff8bcc844
--- /dev/null
+++ b/challenge-193/adam-russell/perl/ch-1.pl
@@ -0,0 +1,18 @@
+use v5.36;
+##
+# You are given an integer, $n > 0.
+# Write a script to find all possible binary numbers of size $n.
+##
+sub binary_numbers_size_n{
+ my($n) = @_;
+ my @numbers = map {
+ sprintf("%0${n}b", $_)
+ } 0 .. 2**$n - 1;
+ return @numbers;
+}
+
+MAIN:{
+ say join(", ", binary_numbers_size_n(2));
+ say join(", ", binary_numbers_size_n(3));
+ say join(", ", binary_numbers_size_n(4));
+} \ No newline at end of file
diff --git a/challenge-193/adam-russell/perl/ch-2.pl b/challenge-193/adam-russell/perl/ch-2.pl
new file mode 100644
index 0000000000..b81a4231c0
--- /dev/null
+++ b/challenge-193/adam-russell/perl/ch-2.pl
@@ -0,0 +1,38 @@
+use v5.36;
+##
+# You are given a list of strings of same length, @s.
+# Write a script to find the odd string in the given list.
+# Use positional alphabet values starting with 0, i.e. a = 0, b = 1, ... z = 25.
+##
+sub odd_string{
+ my(@strings) = @_;
+ my %differences;
+ for my $string (@strings){
+ my $current;
+ my $previous;
+ my @differences;
+ map {
+ unless($previous){
+ $previous = $_;
+ }
+ else{
+ $current = $_;
+ push @differences, ord($current) - ord($previous);
+ $previous = $current;
+ }
+ } split(//, $string);
+ my $key = join(",", @differences);
+ my $size_before = keys %differences;
+ $differences{$key} = undef;
+ my $size_after = keys %differences;
+ return $string if $size_before > 0 && $size_after - $size_before == 1;
+ }
+ return undef;
+}
+
+MAIN:{
+ say odd_string(qw/adc wzy abc/);
+ say odd_string(qw/aaa bob ccc ddd/);
+ say odd_string(qw/aaaa bbbb cccc dddd/) || "no odd string found";
+ say odd_string(qw/aaaa bbob cccc dddd/);
+} \ No newline at end of file
diff --git a/challenge-193/adam-russell/prolog/ch-1.p b/challenge-193/adam-russell/prolog/ch-1.p
new file mode 100644
index 0000000000..65fa25e681
--- /dev/null
+++ b/challenge-193/adam-russell/prolog/ch-1.p
@@ -0,0 +1,11 @@
+binary --> [].
+binary --> digit, binary.
+digit --> [0]; [1].
+
+binary_numbers_size_n(N, BinaryNumbers):-
+ length(Binary, N),
+ findall(Binary, phrase(binary, Binary), BinaryNumbers).
+
+main:-
+ binary_numbers_size_n(2, BinaryNumbers),
+ write(BinaryNumbers), nl. \ No newline at end of file
diff --git a/challenge-193/adam-russell/prolog/ch-2.p b/challenge-193/adam-russell/prolog/ch-2.p
new file mode 100644
index 0000000000..ec04bf202b
--- /dev/null
+++ b/challenge-193/adam-russell/prolog/ch-2.p
@@ -0,0 +1,16 @@
+string_differences(String, Differences):-
+ atom_codes(String, Codes),
+ string_differences(Codes, [], Differences).
+string_differences([_|[]], Differences, Differences).
+string_differences([C0, C1|T], DifferenceAccum, Differences):-
+ Difference is C1 - C0,
+ string_differences([C1|T], [Difference|DifferenceAccum], Differences).
+
+odd_string(Strings, OddString):-
+ maplist(string_differences, Strings, Differences),
+ member(Difference, Differences),
+ delete(Differences, Difference, UpdatedDifferences),
+ length(UpdatedDifferences, UpdatedDifferencesLength),
+ UpdatedDifferencesLength > 1,
+ nth(N, Differences, Difference),
+ nth(N, Strings, OddString). \ No newline at end of file