aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-285/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-285/jaldhar-h-vyas/perl/ch-1.pl25
-rwxr-xr-xchallenge-285/jaldhar-h-vyas/perl/ch-2.pl32
-rwxr-xr-xchallenge-285/jaldhar-h-vyas/raku/ch-1.sh3
-rwxr-xr-xchallenge-285/jaldhar-h-vyas/raku/ch-2.raku33
5 files changed, 94 insertions, 0 deletions
diff --git a/challenge-285/jaldhar-h-vyas/blog.txt b/challenge-285/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..3a342f4330
--- /dev/null
+++ b/challenge-285/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2024/09/perl_weekly_challenge_week_285.html
diff --git a/challenge-285/jaldhar-h-vyas/perl/ch-1.pl b/challenge-285/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..48f35569c3
--- /dev/null
+++ b/challenge-285/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+use v5.38;
+
+sub setDifference($arr1, $arr2) {
+ my %difference = map { $_ => 0 } @{$arr1};
+
+ for my $elem (@{$arr2}) {
+ if (exists $difference{$elem}) {
+ $difference{$elem}++;
+ }
+ }
+
+ return sort grep { !$difference{$_} } keys %difference;
+}
+
+my @first;
+my @second;
+
+for my $arg (@ARGV) {
+ @_ = split /\s+/, $arg;
+ push @first, $_[0];
+ push @second, $_[1];
+}
+
+say join q{ }, setDifference(\@second, \@first); \ No newline at end of file
diff --git a/challenge-285/jaldhar-h-vyas/perl/ch-2.pl b/challenge-285/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..f394ead681
--- /dev/null
+++ b/challenge-285/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+use v5.38;
+no warnings qw/ recursion /;
+use constant PENNY => 1;
+use constant NICKEL => 5;
+use constant DIME => 10;
+use constant QUARTER => 25;
+use constant HALFDOLLAR => 50;
+
+sub changeCombinations($amount, $largestCoin){
+ state @coins=(PENNY, NICKEL, DIME, QUARTER, HALFDOLLAR);
+ if ($largestCoin > $amount) {
+ return 0;
+ }
+
+ if ($largestCoin == $amount) {
+ return 1;
+ }
+
+ my $total;
+
+ for my $coin (grep {$_ <= $largestCoin} @coins) {
+ $total += changeCombinations($amount - $largestCoin, $coin);
+ }
+
+ return $total;
+}
+
+my ($amount) = @ARGV;
+my $largestCoin = HALFDOLLAR;
+
+say changeCombinations($amount + $largestCoin, $largestCoin)
diff --git a/challenge-285/jaldhar-h-vyas/raku/ch-1.sh b/challenge-285/jaldhar-h-vyas/raku/ch-1.sh
new file mode 100755
index 0000000000..4e779662a6
--- /dev/null
+++ b/challenge-285/jaldhar-h-vyas/raku/ch-1.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+raku -e 'my @a=@*ARGS.words.pairup;(@a.map({$_.value})∖@a.map({$_.key})).keys.join.say' "$@" \ No newline at end of file
diff --git a/challenge-285/jaldhar-h-vyas/raku/ch-2.raku b/challenge-285/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..6c53fe4b65
--- /dev/null
+++ b/challenge-285/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,33 @@
+#!/usr/bin/raku
+
+constant PENNY = 1;
+constant NICKEL = 5;
+constant DIME = 10;
+constant QUARTER = 25;
+constant HALFDOLLAR = 50;
+
+sub changeCombinations($amount, $largestCoin){
+ constant @coins = (HALFDOLLAR, QUARTER, DIME, NICKEL, PENNY);
+
+ if $largestCoin > $amount {
+ return 0;
+ }
+
+ if $largestCoin == $amount {
+ return 1;
+ }
+
+ my $total;
+
+ for @coins.grep({ $_ <= $largestCoin }) -> $coin {
+ $total += changeCombinations($amount - $largestCoin, $coin);
+ }
+
+ return $total;
+}
+
+sub MAIN(
+ Int $amount
+) {
+ say changeCombinations($amount + HALFDOLLAR, HALFDOLLAR);
+} \ No newline at end of file