aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-07-27 23:38:43 +0100
committerGitHub <noreply@github.com>2020-07-27 23:38:43 +0100
commit6e37cf7a522f5a71f9135c0597c71adf1f62d50a (patch)
treea1e89a412ca1583516b7984a954a25a2ec3dfc16
parent2b4a3922baba98057f6ff2bb26e2ffaffa512633 (diff)
parent87cb3c5ff91c57a3a030889c3b0a09d7bb521873 (diff)
downloadperlweeklychallenge-club-6e37cf7a522f5a71f9135c0597c71adf1f62d50a.tar.gz
perlweeklychallenge-club-6e37cf7a522f5a71f9135c0597c71adf1f62d50a.tar.bz2
perlweeklychallenge-club-6e37cf7a522f5a71f9135c0597c71adf1f62d50a.zip
Merge pull request #1988 from Firedrake/rogerbw-challenge-071
Solution to challenge #71.1.
-rw-r--r--challenge-071/roger-bell-west/perl/ch-1.pl37
-rw-r--r--challenge-071/roger-bell-west/raku/ch-1.p631
2 files changed, 68 insertions, 0 deletions
diff --git a/challenge-071/roger-bell-west/perl/ch-1.pl b/challenge-071/roger-bell-west/perl/ch-1.pl
new file mode 100644
index 0000000000..1917324d6e
--- /dev/null
+++ b/challenge-071/roger-bell-west/perl/ch-1.pl
@@ -0,0 +1,37 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+use List::Util qw(shuffle);
+use Test::More tests => 2;
+
+is_deeply(peaks(18, 45, 38, 25, 10, 7, 21, 6, 28, 48),
+ [45, 21, 48],
+ 'peaks 1',
+ );
+
+is_deeply(peaks(47, 11, 32, 8, 1, 9, 39, 14, 36, 23),
+ [47, 32, 39, 36],
+ 'peaks 2',
+ );
+
+sub genseq {
+ my $n=shift;
+ my @out=shuffle(1..50);
+ splice @out,$n;
+ return @out;
+}
+
+sub peaks {
+ my @list=@_;
+ my @out;
+ foreach my $n (0..$#list) {
+ if (($n==0 || $list[$n]>$list[$n-1])
+ &&
+ ($n==$#list || $list[$n]>$list[$n+1])) {
+ push @out,$list[$n];
+ }
+ }
+ return \@out;
+}
diff --git a/challenge-071/roger-bell-west/raku/ch-1.p6 b/challenge-071/roger-bell-west/raku/ch-1.p6
new file mode 100644
index 0000000000..44dcb5378a
--- /dev/null
+++ b/challenge-071/roger-bell-west/raku/ch-1.p6
@@ -0,0 +1,31 @@
+#! /usr/bin/perl6
+
+use Test;
+
+plan 2;
+
+is-deeply(peaks((18, 45, 38, 25, 10, 7, 21, 6, 28, 48).List),
+ (45, 21, 48),
+ 'peaks 1',
+ );
+
+is-deeply(peaks((47, 11, 32, 8, 1, 9, 39, 14, 36, 23).List),
+ (47, 32, 39, 36),
+ 'peaks 2',
+ );
+
+sub genseq($n) {
+ return (1..50).pick($n);
+}
+
+sub peaks(@list) {
+ my @out;
+ for (0..@list.end) -> $n {
+ if (($n==0 || @list[$n] > @list[$n-1])
+ &&
+ ($n==@list.end || @list[$n] > @list[$n+1])) {
+ push @out,@list[$n];
+ }
+ }
+ return @out.flat;
+}