aboutsummaryrefslogtreecommitdiff
path: root/challenge-199
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-01-10 18:31:29 +0000
committerGitHub <noreply@github.com>2023-01-10 18:31:29 +0000
commit6d56ad736a52e059f5afd4e644dfb05f737e70e5 (patch)
tree04f30dd39f94d723b880b007471da0c298cf21e5 /challenge-199
parenta85ec266b8fce2b72c1d93660eca336a77efaa43 (diff)
parent0ae92695ac2d905eb58020ac15f2f343feabc4ae (diff)
downloadperlweeklychallenge-club-6d56ad736a52e059f5afd4e644dfb05f737e70e5.tar.gz
perlweeklychallenge-club-6d56ad736a52e059f5afd4e644dfb05f737e70e5.tar.bz2
perlweeklychallenge-club-6d56ad736a52e059f5afd4e644dfb05f737e70e5.zip
Merge pull request #7389 from zapwai/branch-for-challenge-199
Week 199
Diffstat (limited to 'challenge-199')
-rw-r--r--challenge-199/zapwai/perl/ch-1.pl17
-rw-r--r--challenge-199/zapwai/perl/ch-2.pl22
-rw-r--r--challenge-199/zapwai/raku/ch-1.raku15
-rw-r--r--challenge-199/zapwai/raku/ch-2.raku15
4 files changed, 69 insertions, 0 deletions
diff --git a/challenge-199/zapwai/perl/ch-1.pl b/challenge-199/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..9df9550e44
--- /dev/null
+++ b/challenge-199/zapwai/perl/ch-1.pl
@@ -0,0 +1,17 @@
+use v5.30.0;
+my @list = (1,2,3,1,1,3);
+#my @list =(1,2,3);
+my $cnt = 0;
+my $str;
+for my $this (0 .. $#list - 1) {
+ for my $that ($this + 1 .. $#list) {
+ if ($list[$this] == $list[$that]) {
+ $str .= "($this, $that)\n";
+ $cnt++;
+ }
+ }
+}
+say "Input: (". join(",",@list).")";
+say "Output: $cnt";
+chomp $str;
+say $str;
diff --git a/challenge-199/zapwai/perl/ch-2.pl b/challenge-199/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..0e51f64601
--- /dev/null
+++ b/challenge-199/zapwai/perl/ch-2.pl
@@ -0,0 +1,22 @@
+use v5.30.0;
+my @list = (3,0,1,1,9,7);
+my $x = 7;
+my $y = 2;
+my $z = 3;
+say "Input: (".join(",",@list).")";
+print "Output: ";
+my $cnt = 0;
+my $str;
+for my $i ( 0 .. $#list - 2) {
+ for my $j ( $i + 1 .. $#list - 1) {
+ for my $k ( $j + 1 .. $#list) {
+ if ( (abs($list[$i] - $list[$j]) <= $x) && (abs($list[$j] - $list[$k]) <= $y) && (abs($list[$i] - $list[$k]) <= $z) ) {
+ $str .= "($list[$i],$list[$j],$list[$k]) \t [(i,j,k) = ($i,$j,$k)]\n";
+ $cnt++;
+ }
+ }
+ }
+}
+
+chomp $str;
+say "$cnt friendly triplets...\n$str";
diff --git a/challenge-199/zapwai/raku/ch-1.raku b/challenge-199/zapwai/raku/ch-1.raku
new file mode 100644
index 0000000000..0e79cc3b1e
--- /dev/null
+++ b/challenge-199/zapwai/raku/ch-1.raku
@@ -0,0 +1,15 @@
+my @list = (1,2,3,1,1,3);
+#my @list=(1,2,3);
+say "Input: (" ~ join(",", @list) ~ ")";
+my $cnt = 0 ;
+my $str;
+loop (my $this = 0; $this < @list.elems - 1; $this++) {
+ loop (my $that = $this + 1; $that < @list.elems; $that++) {
+ if @list[$this] == @list[$that] {
+ $cnt++;
+ $str ~= "($this, $that)\n";
+ }
+ }
+}
+say "Output: $cnt";
+say $str if ($str);
diff --git a/challenge-199/zapwai/raku/ch-2.raku b/challenge-199/zapwai/raku/ch-2.raku
new file mode 100644
index 0000000000..2a4ebbcf09
--- /dev/null
+++ b/challenge-199/zapwai/raku/ch-2.raku
@@ -0,0 +1,15 @@
+my @list = (3,0,1,1,9,7);
+my ($x, $y, $z) = (7, 2, 3);
+my $cnt = 0;
+my $str;
+loop (my $i = 0; $i < @list.elems - 2; $i++) {
+ loop (my $j = $i + 1; $j < @list.elems - 1; $j++) {
+ loop (my $k = $j + 1; $k < @list.elems; $k++) {
+ if (abs(@list[$i] - @list[$j]) <= $x && abs(@list[$j] - @list[$k]) <= $y && abs(@list[$k] - @list[$i]) <= $z) {
+ $str ~= "("~join(",",@list[$i],@list[$j],@list[$k])~") \t [i:$i,j:$j,k:$k]\n";
+ $cnt++;
+ }
+ }}}
+say "Input: (" ~ join(",", @list) ~ ")";
+say "Output: $cnt";
+say chomp $str;