diff options
| author | Jaldhar H. Vyas <jaldhar@braincells.com> | 2024-04-06 23:13:35 -0400 |
|---|---|---|
| committer | Jaldhar H. Vyas <jaldhar@braincells.com> | 2024-04-06 23:13:35 -0400 |
| commit | 1addfe5eb08b1da0a76851beba8dc1fd754735eb (patch) | |
| tree | b10404a36d4f6fb87aa07707c87e2747b789181e /challenge-262 | |
| parent | afabe146fd8adc898559eefad2d6875b3d5aa675 (diff) | |
| download | perlweeklychallenge-club-1addfe5eb08b1da0a76851beba8dc1fd754735eb.tar.gz perlweeklychallenge-club-1addfe5eb08b1da0a76851beba8dc1fd754735eb.tar.bz2 perlweeklychallenge-club-1addfe5eb08b1da0a76851beba8dc1fd754735eb.zip | |
Challenge 262 by Jaldhar H. Vyas.
Diffstat (limited to 'challenge-262')
| -rw-r--r-- | challenge-262/jaldhar-h-vyas/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-262/jaldhar-h-vyas/perl/ch-1.pl | 20 | ||||
| -rwxr-xr-x | challenge-262/jaldhar-h-vyas/perl/ch-2.pl | 33 | ||||
| -rwxr-xr-x | challenge-262/jaldhar-h-vyas/raku/ch-1.sh | 3 | ||||
| -rwxr-xr-x | challenge-262/jaldhar-h-vyas/raku/ch-2.raku | 13 |
5 files changed, 70 insertions, 0 deletions
diff --git a/challenge-262/jaldhar-h-vyas/blog.txt b/challenge-262/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..b46755052c --- /dev/null +++ b/challenge-262/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2024/04/perl_weekly_challenge_week_262.html diff --git a/challenge-262/jaldhar-h-vyas/perl/ch-1.pl b/challenge-262/jaldhar-h-vyas/perl/ch-1.pl new file mode 100755 index 0000000000..e4ae03f2cc --- /dev/null +++ b/challenge-262/jaldhar-h-vyas/perl/ch-1.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + + +my @ints = @ARGV; + +my $positive = 0; +my $negative = 0; + +for my $n (@ints) { + if ($n > 0) { + $positive++; + } elsif ($n < 0) { + $negative++; + } +} + +say 0+($positive > $negative) ? $positive : $negative; + diff --git a/challenge-262/jaldhar-h-vyas/perl/ch-2.pl b/challenge-262/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..af971a18ef --- /dev/null +++ b/challenge-262/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +sub combinations { + my @list = @{$_[0]}; + my $length = $_[1]; + + if ($length <= 1) { + return map [$_], @list; + } + + my @combos; + + for (my $i = 0; $i + $length <= scalar @list; $i++) { + my $val = $list[$i]; + my @rest = @list[$i + 1 .. $#list]; + for my $c (combinations(\@rest, $length - 1)) { + push @combos, [$val, @{$c}] ; + } + } + + return @combos; +} + +my $k = shift; +my @ints = @ARGV; + +say + scalar + grep { $ints[$_->[0]] == $ints[$_->[1]] && ($_->[0] * $_->[1]) % $k == 0 } + combinations([ keys @ints ], 2); + diff --git a/challenge-262/jaldhar-h-vyas/raku/ch-1.sh b/challenge-262/jaldhar-h-vyas/raku/ch-1.sh new file mode 100755 index 0000000000..341d1c99e9 --- /dev/null +++ b/challenge-262/jaldhar-h-vyas/raku/ch-1.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +raku -e '@*ARGS.classify({if $_ < 0 {q{n}} elsif $_ > 0 {q{p}}else{q{0}}},:into(my %a));max(%a<n>.elems,%a<p>.elems).say' "$@"
\ No newline at end of file diff --git a/challenge-262/jaldhar-h-vyas/raku/ch-2.raku b/challenge-262/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..bb17d9f231 --- /dev/null +++ b/challenge-262/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,13 @@ +#!/usr/bin/raku + +sub MAIN( + $k, + *@ints +) { + @ints + .keys + .combinations(2) + .grep({ @ints[@$_[0]] == @ints[@$_[1]] && ([*] @$_) %% $k }) + .elems + .say; +}
\ No newline at end of file |
