aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-322/adam-russell/blog.txt1
-rw-r--r--challenge-322/adam-russell/perl/ch-1.pl34
-rw-r--r--challenge-322/adam-russell/perl/ch-2.pl29
3 files changed, 64 insertions, 0 deletions
diff --git a/challenge-322/adam-russell/blog.txt b/challenge-322/adam-russell/blog.txt
new file mode 100644
index 0000000000..99ec6c76f2
--- /dev/null
+++ b/challenge-322/adam-russell/blog.txt
@@ -0,0 +1 @@
+http://rabbitfarm.com/cgi-bin/blosxom/perl/2025/05/25
diff --git a/challenge-322/adam-russell/perl/ch-1.pl b/challenge-322/adam-russell/perl/ch-1.pl
new file mode 100644
index 0000000000..39a4d3c4fc
--- /dev/null
+++ b/challenge-322/adam-russell/perl/ch-1.pl
@@ -0,0 +1,34 @@
+
+
+use v5.40;
+
+
+ sub string_format{
+ my($s, $i) = @_;
+ my @s = split //, $s;
+ my @t = ([]);
+ {
+ my $s_ = pop @s;
+ unless($s_ eq q/-/){
+ my $t_ = shift @t;
+ if(@{$t_} == $i){
+ unshift @t, $t_;
+ unshift @t, [$s_];
+ }
+ else{
+ unshift @{$t_}, $s_;
+ unshift @t, $t_;
+ }
+ }
+ redo if @s;
+ }
+ return join(q/-/, map {join q//, @{$_}} @t);
+ }
+
+
+MAIN:{
+ say string_format q/ABC-D-E-F/, 3;
+ say string_format q/A-BC-D-E/, 2;
+ say string_format q/-A-B-CD-E/, 4;
+}
+
diff --git a/challenge-322/adam-russell/perl/ch-2.pl b/challenge-322/adam-russell/perl/ch-2.pl
new file mode 100644
index 0000000000..b8000d6fb4
--- /dev/null
+++ b/challenge-322/adam-russell/perl/ch-2.pl
@@ -0,0 +1,29 @@
+
+
+use v5.40;
+
+
+ sub number_larger{
+ my($x, $unique) = @_;
+ return @{$unique} - grep {$_ > $x} @{$unique};
+ }
+
+
+ sub rank_array{
+ my(@i) = @_;
+ my %h;
+ my @unique = ();
+
+ do{$h{$_} = undef} for @i;
+
+ @unique = keys %h;
+ return map {number_larger $_, [@unique]} @i;
+ }
+
+
+MAIN:{
+ say q/(/ . join(q/, /, (rank_array 55, 22, 44, 33)) . q/)/;
+ say q/(/ . join(q/, /, (rank_array 10, 10, 10)) . q/)/;
+ say q/(/ . join(q/, /, (rank_array 5, 1, 1, 4, 3)) . q/)/;
+}
+