aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-08-03 04:50:06 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-08-03 04:50:06 +0100
commit8c2f5fd585d45d45a93bea8031ad0a30c9534218 (patch)
tree4f4581e67a98e5d8efb1b21588b3c6bdd30a3630
parente7ac85a1fd02d06401caccf9da639c6fa1ca3774 (diff)
downloadperlweeklychallenge-club-8c2f5fd585d45d45a93bea8031ad0a30c9534218.tar.gz
perlweeklychallenge-club-8c2f5fd585d45d45a93bea8031ad0a30c9534218.tar.bz2
perlweeklychallenge-club-8c2f5fd585d45d45a93bea8031ad0a30c9534218.zip
- Tidied up solutions by Colin Crain.
-rw-r--r--challenge-071/colin-crain/perl/ch-1.pl10
-rw-r--r--challenge-071/colin-crain/raku/ch-1.raku3
2 files changed, 9 insertions, 4 deletions
diff --git a/challenge-071/colin-crain/perl/ch-1.pl b/challenge-071/colin-crain/perl/ch-1.pl
index e6af8e7afe..8a492d223f 100644
--- a/challenge-071/colin-crain/perl/ch-1.pl
+++ b/challenge-071/colin-crain/perl/ch-1.pl
@@ -31,10 +31,14 @@ use feature ":5.26";
my $n = shift @ARGV // 10;
-## encapsulating the arr in 0s first
-## makes the comparisons at the ends of cleaner
+die "cannot create more than 50 unique elements" if $n > 50;
+
+## make a list of n unique numbers
+## --> encapsulating the arr in 0s
+## makes the comparisons at the ends easy
+my @pool = (1..50);
my @arr = (0);
-push @arr, int(rand(50))+1 for (1..$n);
+push @arr, splice( @pool, int(rand(@pool)) , 1 ) while (@arr < $n+1);
push @arr, 0;
say "input array: @arr[1..@arr-2]";
diff --git a/challenge-071/colin-crain/raku/ch-1.raku b/challenge-071/colin-crain/raku/ch-1.raku
index f7b0d92cbc..f32017af86 100644
--- a/challenge-071/colin-crain/raku/ch-1.raku
+++ b/challenge-071/colin-crain/raku/ch-1.raku
@@ -35,7 +35,8 @@ sub MAIN (Int $n where {$n > 0} = 10 ) {
# create our random array:
# bookending the arr in 0s
# makes the comparisons at the ends cleaner
- my @a = 0, |(^$n).map({ (1..50).pick }), 0 ;
+
+ my @a = 0, |(1..50).pick($n), 0 ;
say "input array: @a[1..@a-2]";