aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-141/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-141/jaldhar-h-vyas/perl/ch-1.pl28
-rwxr-xr-xchallenge-141/jaldhar-h-vyas/perl/ch-2.pl39
-rwxr-xr-xchallenge-141/jaldhar-h-vyas/raku/ch-1.raku20
-rwxr-xr-xchallenge-141/jaldhar-h-vyas/raku/ch-2.raku13
5 files changed, 101 insertions, 0 deletions
diff --git a/challenge-141/jaldhar-h-vyas/blog.txt b/challenge-141/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..905a6335ab
--- /dev/null
+++ b/challenge-141/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2021/12/perl_weekly_challenge_week_141.html
diff --git a/challenge-141/jaldhar-h-vyas/perl/ch-1.pl b/challenge-141/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..0c447a7013
--- /dev/null
+++ b/challenge-141/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+use 5.020;
+use warnings;
+
+sub hasEightDivisors {
+ my ($n) = @_;
+ my $count = 0;
+
+ for my $i (1 .. $n) {
+ if ($n % $i == 0) {
+ $count++;
+ }
+ }
+
+ return $count == 8;
+}
+
+my @eightDivisors;
+my $n = 2;
+
+while (scalar @eightDivisors < 10) {
+ if (hasEightDivisors($n)) {
+ push @eightDivisors, $n;
+ }
+ $n++;
+}
+
+say join q{, }, @eightDivisors; \ No newline at end of file
diff --git a/challenge-141/jaldhar-h-vyas/perl/ch-2.pl b/challenge-141/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..6a3586c472
--- /dev/null
+++ b/challenge-141/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+use 5.020;
+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;
+}
+
+if (scalar @ARGV != 2) {
+ die "Need two integers\n";
+}
+
+my ($m, $n) = @ARGV;
+
+my @digits = split //, $m;
+my @combinations;
+
+for my $i (1 .. scalar @digits - 1) {
+ push @combinations, map { join q{}, @{$_}; } combinations(\@digits, $i);
+}
+
+say scalar grep { $_ % $n == 0; } @combinations; \ No newline at end of file
diff --git a/challenge-141/jaldhar-h-vyas/raku/ch-1.raku b/challenge-141/jaldhar-h-vyas/raku/ch-1.raku
new file mode 100755
index 0000000000..724126dbdb
--- /dev/null
+++ b/challenge-141/jaldhar-h-vyas/raku/ch-1.raku
@@ -0,0 +1,20 @@
+#!/usr/bin/raku
+
+sub hasEightDivisors(Int $n) {
+ return (1 .. $n).grep({ $n %% $_; }).elems == 8;
+}
+
+sub MAIN() {
+
+ my @eightDivisors;
+ my $n = 2;
+
+ while @eightDivisors.elems < 10 {
+ if hasEightDivisors($n) {
+ @eightDivisors.push($n);
+ }
+ $n++;
+ }
+
+ say join q{, }, @eightDivisors;
+} \ No newline at end of file
diff --git a/challenge-141/jaldhar-h-vyas/raku/ch-2.raku b/challenge-141/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..8749e0e4d0
--- /dev/null
+++ b/challenge-141/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,13 @@
+#!/usr/bin/raku
+
+sub MAIN(
+ $m,
+ $n
+) {
+ $m.comb
+ .combinations(1 ..^ $m.chars)
+ .map({ $_.join; })
+ .grep({ $_ %% $n; })
+ .elems
+ .say;
+}