diff options
| -rw-r--r-- | challenge-199/zapwai/perl/ch-1.pl | 17 | ||||
| -rw-r--r-- | challenge-199/zapwai/perl/ch-2.pl | 22 | ||||
| -rw-r--r-- | challenge-199/zapwai/raku/ch-1.raku | 15 | ||||
| -rw-r--r-- | challenge-199/zapwai/raku/ch-2.raku | 15 |
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; |
