aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-245/adam-russell/blog.txt1
-rw-r--r--challenge-245/adam-russell/blog1.txt1
-rw-r--r--challenge-245/adam-russell/perl/ch-1.pl21
-rw-r--r--challenge-245/adam-russell/perl/ch-2.pl28
-rw-r--r--challenge-245/adam-russell/prolog/ch-1.p6
-rw-r--r--challenge-245/adam-russell/prolog/ch-2.p10
6 files changed, 67 insertions, 0 deletions
diff --git a/challenge-245/adam-russell/blog.txt b/challenge-245/adam-russell/blog.txt
new file mode 100644
index 0000000000..352d19817d
--- /dev/null
+++ b/challenge-245/adam-russell/blog.txt
@@ -0,0 +1 @@
+http://www.rabbitfarm.com/cgi-bin/blosxom/perl/2023/12/03 \ No newline at end of file
diff --git a/challenge-245/adam-russell/blog1.txt b/challenge-245/adam-russell/blog1.txt
new file mode 100644
index 0000000000..12b7ddad27
--- /dev/null
+++ b/challenge-245/adam-russell/blog1.txt
@@ -0,0 +1 @@
+http://www.rabbitfarm.com/cgi-bin/blosxom/prolog/2023/12/03 \ No newline at end of file
diff --git a/challenge-245/adam-russell/perl/ch-1.pl b/challenge-245/adam-russell/perl/ch-1.pl
new file mode 100644
index 0000000000..eb346f69e3
--- /dev/null
+++ b/challenge-245/adam-russell/perl/ch-1.pl
@@ -0,0 +1,21 @@
+use v5.38;
+##
+# You are given two array of languages and its popularity.
+# Write a script to sort the language based on popularity.
+##
+use Thread;
+sub sort_language{
+ my @language = @{$_[0]};
+ my @popularity = @{$_[1]};
+ my @threads;
+ do{
+ push @threads, Thread->new(
+ sub{sleep($popularity[$_]); say $language[$_]}
+ );
+ } for 0 .. @popularity - 1;
+ do{$_ -> join()} for @threads;
+}
+
+MAIN:{
+ sort_language [qw/perl c python/], [2, 1, 3];
+} \ No newline at end of file
diff --git a/challenge-245/adam-russell/perl/ch-2.pl b/challenge-245/adam-russell/perl/ch-2.pl
new file mode 100644
index 0000000000..5908acae8d
--- /dev/null
+++ b/challenge-245/adam-russell/perl/ch-2.pl
@@ -0,0 +1,28 @@
+use v5.38;
+##
+# You are given an array of integers >= 0.
+# Write a script to return the largest number formed by concatenating
+# some of the given integers in any order which is also multiple of 3.
+# Return -1 if none found.
+##
+use Algorithm::Permute;
+sub largest_of_three{
+ my @digits = @_;
+ my $largest = -1;
+ do{
+ my $indices = $_;
+ my @sub_digits = @digits[grep{vec($indices, $_, 1) == 1} 0 .. @digits - 1];
+ my $permutor = Algorithm::Permute->new([@sub_digits]);
+ while(my @permutation = $permutor->next()){
+ my $d = join q//, @permutation;
+ $largest = $d if $d > $largest && $d % 3 == 0;
+ }
+ } for 1 .. 2**@digits - 1;
+ return $largest;
+}
+
+MAIN:{
+ say largest_of_three 8, 1, 9;
+ say largest_of_three 8, 6, 7, 1, 0;
+ say largest_of_three 1;
+} \ No newline at end of file
diff --git a/challenge-245/adam-russell/prolog/ch-1.p b/challenge-245/adam-russell/prolog/ch-1.p
new file mode 100644
index 0000000000..6d2e6b95b3
--- /dev/null
+++ b/challenge-245/adam-russell/prolog/ch-1.p
@@ -0,0 +1,6 @@
+make_pairs(K, V, K-V).
+
+sort_language(Languages, Popularity, SortedLanguages):-
+ maplist(make_pairs, Popularity, Languages, PopularityLanguages),
+ keysort(PopularityLanguages, SortedPopularityLanguages),
+ findall(Language, member(_-Language, SortedPopularityLanguages), SortedLanguages). \ No newline at end of file
diff --git a/challenge-245/adam-russell/prolog/ch-2.p b/challenge-245/adam-russell/prolog/ch-2.p
new file mode 100644
index 0000000000..3bb13581f5
--- /dev/null
+++ b/challenge-245/adam-russell/prolog/ch-2.p
@@ -0,0 +1,10 @@
+largest_of_three(Numbers, LargestOfThree):-
+ findall(Number,(
+ sublist(SubList, Numbers),
+ \+ SubList = [],
+ permutation(SubList, SubListPermutation),
+ number_codes(Number, SubListPermutation),
+ 0 is Number mod 3), NumbersOfThree),
+ ((NumbersOfThree = [], LargestOfThree = -1);
+ (max_list(NumbersOfThree, LargestOfThree))).
+ \ No newline at end of file