aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-12-26 01:25:25 +0000
committerGitHub <noreply@github.com>2022-12-26 01:25:25 +0000
commitdffef676d5f5a18156d8502de760f66b4a27de29 (patch)
tree12ee517053f39499bc2475a70955c39454c5f9db
parentdbf3892dcde85f90f1d809e9519e6e11643fc099 (diff)
parent45c8bce3acc91caf3724e0acd52ed75a51c69f10 (diff)
downloadperlweeklychallenge-club-dffef676d5f5a18156d8502de760f66b4a27de29.tar.gz
perlweeklychallenge-club-dffef676d5f5a18156d8502de760f66b4a27de29.tar.bz2
perlweeklychallenge-club-dffef676d5f5a18156d8502de760f66b4a27de29.zip
Merge pull request #7300 from jaldhar/challenge-196
Challenge 196 by Jaldhar H. Vyas.
-rw-r--r--challenge-196/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-196/jaldhar-h-vyas/perl/ch-1.pl18
-rwxr-xr-xchallenge-196/jaldhar-h-vyas/perl/ch-2.pl26
-rwxr-xr-xchallenge-196/jaldhar-h-vyas/raku/ch-1.raku18
-rwxr-xr-xchallenge-196/jaldhar-h-vyas/raku/ch-2.raku26
5 files changed, 89 insertions, 0 deletions
diff --git a/challenge-196/jaldhar-h-vyas/blog.txt b/challenge-196/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..bd5641591b
--- /dev/null
+++ b/challenge-196/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2022/12/perl_weekly_challenge_week_196.html \ No newline at end of file
diff --git a/challenge-196/jaldhar-h-vyas/perl/ch-1.pl b/challenge-196/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..aed84967d8
--- /dev/null
+++ b/challenge-196/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+use 5.030;
+use warnings;
+
+my @list = @ARGV // die "need a list of integers separated by spaces";
+
+for my $i (0 .. scalar @list - 3) {
+ for my $j ($i + 1 .. scalar @list - 2) {
+ for my $k ($j + 1 .. scalar @list - 1) {
+ if ($list[$i] < $list[$k] && $list[$k] < $list[$j]) {
+ say q{(}, (join q{, }, ($list[$i], $list[$j], $list[$k])), q{)};
+ exit;
+ }
+ }
+ }
+}
+
+say q{()};
diff --git a/challenge-196/jaldhar-h-vyas/perl/ch-2.pl b/challenge-196/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..afd2da9329
--- /dev/null
+++ b/challenge-196/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+use 5.030;
+use warnings;
+
+my @array = @ARGV // die "need a list of integers separated by spaces";
+
+my @allranges;
+my $n = 0;
+
+while ($n < scalar @array - 1) {
+ my $r = $n;
+ my @range = ( $array[$r] );
+ until ($r == scalar @array - 1) {
+ $r++;
+ if ($array[$r] - $array[$r - 1] == 1) {
+ push @range, $array[$r];
+ } else {
+ last;
+ }
+ }
+ $n = $r;
+ push @allranges, \@range;
+}
+
+@allranges = map { "[$_->[0],$_->[-1]]"; } grep { scalar @{$_} > 1 } @allranges;
+say join q{, }, @allranges;
diff --git a/challenge-196/jaldhar-h-vyas/raku/ch-1.raku b/challenge-196/jaldhar-h-vyas/raku/ch-1.raku
new file mode 100755
index 0000000000..1687892504
--- /dev/null
+++ b/challenge-196/jaldhar-h-vyas/raku/ch-1.raku
@@ -0,0 +1,18 @@
+#!/usr/bin/raku
+
+sub MAIN(
+ *@list #= a list of integers
+) {
+ for 0 .. @list.end - 2 -> $i, $j, $k {
+ for $i ^.. @list.end - 1 -> $j {
+ for $j ^.. @list.end -> $k {
+ if @list[$i] < @list[$k] && @list[$k] < @list[$j] {
+ say "({(@list[$i], @list[$j], @list[$k]).join(q{, })})";
+ exit;
+ }
+ }
+ }
+ }
+
+ say '()';
+} \ No newline at end of file
diff --git a/challenge-196/jaldhar-h-vyas/raku/ch-2.raku b/challenge-196/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..039594c980
--- /dev/null
+++ b/challenge-196/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,26 @@
+#!/usr/bin/raku
+
+sub MAIN(
+ *@array #= a list of integers
+) {
+ my @allranges;
+ my $n = 0;
+
+ while $n < @array.end {
+ my $r = $n;
+ my @range = ( @array[$r] );
+ until $r == @array.end {
+ $r++;
+ if @array[$r] - @array[$r - 1] == 1 {
+ @range.push(@array[$r]);
+ } else {
+ last;
+ }
+ }
+ $n = $r;
+ @allranges.push(@range);
+ }
+
+ @allranges = @allranges.grep({ @$_.elems > 1 }).map({ "[{@$_[0]},{@$_[*-1]}]"; });
+ say @allranges.join(q{, });
+} \ No newline at end of file