aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-08-02 13:43:46 +0100
committerGitHub <noreply@github.com>2023-08-02 13:43:46 +0100
commit331a5dd2f39439d86f97fd5cfadd660b23145cf0 (patch)
treea7100ea75194a42f20161fd2058c295a9d2fd305
parentb658dc62f92bb59e0d9f55a7fcc87ff2876abac0 (diff)
parent5e43c4f39c15b90ee1fd43b314d12472bc066587 (diff)
downloadperlweeklychallenge-club-331a5dd2f39439d86f97fd5cfadd660b23145cf0.tar.gz
perlweeklychallenge-club-331a5dd2f39439d86f97fd5cfadd660b23145cf0.tar.bz2
perlweeklychallenge-club-331a5dd2f39439d86f97fd5cfadd660b23145cf0.zip
Merge pull request #8495 from andemark/challenge-228-Raku
Challenge 228 Solutions (Perl and Raku)
-rw-r--r--challenge-228/mark-anderson/perl/ch-1.pl17
-rw-r--r--challenge-228/mark-anderson/perl/ch-2.pl25
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-228/mark-anderson/perl/ch-1.pl b/challenge-228/mark-anderson/perl/ch-1.pl
new file mode 100644
index 0000000000..3e5bc20ff8
--- /dev/null
+++ b/challenge-228/mark-anderson/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+use v5.32;
+use List::Util qw/sum0/;
+use Test::More;
+use experimental qw/signatures/;
+
+is unique_sum(2,1,3,2), 4;
+is unique_sum(1,1,1,1), 0;
+is unique_sum(2,1,3,4), 10;
+done_testing;
+
+sub unique_sum(@a)
+{
+ my %bag;
+ $bag{$_}++ for @a;
+ sum0 grep { $bag{$_} == 1 } keys %bag
+}
diff --git a/challenge-228/mark-anderson/perl/ch-2.pl b/challenge-228/mark-anderson/perl/ch-2.pl
new file mode 100644
index 0000000000..f5be9a5542
--- /dev/null
+++ b/challenge-228/mark-anderson/perl/ch-2.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+use v5.32;
+use List::Util qw/min/;
+use List::MoreUtils qw/first_index/;
+use Test::More;
+use experimental qw/signatures/;
+
+is empty_array(3,4,2), 5;
+is empty_array(1,2,3), 3;
+is empty_array(16,17,8,15,13,11,19,5,12,6,20,2,4,10,3,14,1,7,9,18), 127;
+done_testing;
+
+sub empty_array(@a)
+{
+ my $total;
+
+ while(@a)
+ {
+ my $i = first_index { $_ == min @a } @a;
+ @a = (@a[$i+1..$#a], @a[0..$i-1]);
+ $total += $i+1
+ }
+
+ $total
+}