aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaldhar H. Vyas <jaldhar@braincells.com>2022-07-03 00:00:00 -0400
committerJaldhar H. Vyas <jaldhar@braincells.com>2022-07-03 00:00:00 -0400
commit8d8b5a46e4d06ee3d9466b073cc83d7014231ab3 (patch)
tree67108e607c774d68b3f19f7df1586e1eba3c044a
parent528df4580b5f97f3826c34a1d6c3701af051fa19 (diff)
downloadperlweeklychallenge-club-8d8b5a46e4d06ee3d9466b073cc83d7014231ab3.tar.gz
perlweeklychallenge-club-8d8b5a46e4d06ee3d9466b073cc83d7014231ab3.tar.bz2
perlweeklychallenge-club-8d8b5a46e4d06ee3d9466b073cc83d7014231ab3.zip
Challenge 171 by Jaldhar H. Vyas.
-rw-r--r--challenge-171/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-171/jaldhar-h-vyas/perl/ch-1.pl34
-rwxr-xr-xchallenge-171/jaldhar-h-vyas/perl/ch-2.pl27
-rwxr-xr-xchallenge-171/jaldhar-h-vyas/raku/ch-1.raku24
-rwxr-xr-xchallenge-171/jaldhar-h-vyas/raku/ch-2.raku16
5 files changed, 102 insertions, 0 deletions
diff --git a/challenge-171/jaldhar-h-vyas/blog.txt b/challenge-171/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..10862e29aa
--- /dev/null
+++ b/challenge-171/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2022/07/perl_weekly_challenge_week_171.html \ No newline at end of file
diff --git a/challenge-171/jaldhar-h-vyas/perl/ch-1.pl b/challenge-171/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..9e9b585bad
--- /dev/null
+++ b/challenge-171/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+use 5.030;
+use warnings;
+
+sub sum {
+ my ($arr) = @_;
+ my $total = 0;
+
+ for my $elem (@{$arr}) {
+ $total += $elem;
+ }
+
+ return $total;
+}
+
+my @abundants;
+my $n = 1;
+
+until (scalar @abundants == 20) {
+ my @divisors;
+ for my $i (1 .. $n / 2) {
+ if ($n % $i == 0) {
+ push @divisors, $i;
+ }
+ }
+
+ if (sum(\@divisors) > $n) {
+ push @abundants, $n;
+ }
+
+ $n += 2;
+}
+
+say join q{, }, @abundants;
diff --git a/challenge-171/jaldhar-h-vyas/perl/ch-2.pl b/challenge-171/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..7c9ebcb2fa
--- /dev/null
+++ b/challenge-171/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+use 5.030;
+use warnings;
+
+sub compose {
+ my ($f, $g) = @_;
+
+ return sub { $f->($g->(@_)); };
+}
+
+sub square {
+ my ($x) = @_;
+
+ return $x * $x;
+}
+
+sub sum {
+ my $total = 0;
+
+ for my $elem (@_) {
+ $total += $elem;
+ }
+
+ return $total;
+}
+
+say compose(\&square, \&sum)->(1,2,3);
diff --git a/challenge-171/jaldhar-h-vyas/raku/ch-1.raku b/challenge-171/jaldhar-h-vyas/raku/ch-1.raku
new file mode 100755
index 0000000000..d1c1211034
--- /dev/null
+++ b/challenge-171/jaldhar-h-vyas/raku/ch-1.raku
@@ -0,0 +1,24 @@
+#!/usr/bin/raku
+
+sub MAIN(
+) {
+ my @abundants;
+ my $n = 1;
+
+ until @abundants.elems == 20 {
+ my @divisors;
+ for 1 .. $n / 2 -> $i {
+ if $n %% $i {
+ @divisors.push($i);
+ }
+ }
+
+ if ([+] @divisors) > $n {
+ @abundants.push($n);
+ }
+
+ $n += 2;
+ }
+
+ @abundants.join(q{, }).say;
+} \ No newline at end of file
diff --git a/challenge-171/jaldhar-h-vyas/raku/ch-2.raku b/challenge-171/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..00f020410c
--- /dev/null
+++ b/challenge-171/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,16 @@
+#!/usr/bin/raku
+
+sub compose(&f, &g) {
+
+ return sub (*@args) { &f(&g(@args)); };
+}
+
+sub square(Int $x) {
+ return $x * $x;
+}
+
+sub sum(*@args) {
+ return [+] @args;
+}
+
+say compose(&square, &sum)(1,2,3);