aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaldhar H. Vyas <jaldhar@braincells.com>2022-12-12 04:27:35 -0500
committerJaldhar H. Vyas <jaldhar@braincells.com>2022-12-12 04:27:35 -0500
commit8137807108c28d3402584bdad443700e1ea001fc (patch)
tree07c60a6575b5383a081a5c155d119c1d8a4ec2b8
parent5333b8bde873a3b1db76959f5b4ad7b68fa811b0 (diff)
downloadperlweeklychallenge-club-8137807108c28d3402584bdad443700e1ea001fc.tar.gz
perlweeklychallenge-club-8137807108c28d3402584bdad443700e1ea001fc.tar.bz2
perlweeklychallenge-club-8137807108c28d3402584bdad443700e1ea001fc.zip
Challenge 194 by Jaldhar H. Vyas.
-rw-r--r--challenge-194/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-194/jaldhar-h-vyas/perl/ch-1.pl27
-rwxr-xr-xchallenge-194/jaldhar-h-vyas/perl/ch-2.pl38
-rwxr-xr-xchallenge-194/jaldhar-h-vyas/raku/ch-1.raku24
-rwxr-xr-xchallenge-194/jaldhar-h-vyas/raku/ch-2.raku20
5 files changed, 110 insertions, 0 deletions
diff --git a/challenge-194/jaldhar-h-vyas/blog.txt b/challenge-194/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..274cfd32da
--- /dev/null
+++ b/challenge-194/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2022/12/perl_weekly_challenge_week_194.html \ No newline at end of file
diff --git a/challenge-194/jaldhar-h-vyas/perl/ch-1.pl b/challenge-194/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..22b4f8e955
--- /dev/null
+++ b/challenge-194/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+use 5.030;
+use warnings;
+use experimental 'switch';
+
+
+
+my $time = shift or die "Need time in the format hh:mm with one missing digit replaced by '?'\n";
+
+given (index $time, '?') {
+ when (0) {
+ given (substr($time, 1, 1)) {
+ when ([0 .. 3]) { say 2; }
+ default { say 1; }
+ }
+ }
+ when (1) {
+ given (substr($time, 0, 1)) {
+ when ([0 .. 1]) { say 9; }
+ when (2) { say 3; }
+ default { die "Illegal time\n"; }
+ }
+ }
+ when (3) { say 5; }
+ when (4) { say 9; }
+ default { die "No ? or ? is in an illegal position.\n"; }
+} \ No newline at end of file
diff --git a/challenge-194/jaldhar-h-vyas/perl/ch-2.pl b/challenge-194/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..c70f928db4
--- /dev/null
+++ b/challenge-194/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+use 5.030;
+use warnings;
+
+sub allEqual {
+ my @arr = @{ shift @_ };
+ my $first = shift @arr;
+
+ for my $elem (@arr) {
+ if ($elem != $first) {
+ return undef;
+ }
+ }
+
+ return 1;
+}
+
+my $s = shift // die "Need a string of alphabetic characters only\n";
+my @chars = split //, $s;
+my $result = 0;
+
+for my $i (0 .. scalar @chars - 1) {
+ my @others = @chars;
+ splice @others, $i, 1;
+
+ my %freq;
+ for my $elem (@others) {
+ $freq{$elem}++;
+ }
+
+
+ if (allEqual([values %freq])) {
+ $result = 1;
+ last;
+ }
+}
+
+say $result;
diff --git a/challenge-194/jaldhar-h-vyas/raku/ch-1.raku b/challenge-194/jaldhar-h-vyas/raku/ch-1.raku
new file mode 100755
index 0000000000..c6856a240e
--- /dev/null
+++ b/challenge-194/jaldhar-h-vyas/raku/ch-1.raku
@@ -0,0 +1,24 @@
+#!/usr/bin/raku
+
+sub MAIN (
+ $time #= time in the format hh:mm with one missing digit replaced by '?'
+) {
+ given $time.index('?') {
+ when 0 {
+ given ($time.substr(1, 1)) {
+ when 0 .. 3 { say 2; }
+ default { say 1; }
+ }
+ }
+ when 1 {
+ given $time.substr(0, 1) {
+ when 0 .. 1 { say 9; }
+ when 2 { say 3; }
+ default { die "Illegal time\n"; }
+ }
+ }
+ when 3 { say 5; }
+ when 4 { say 9; }
+ default { die "No ? or ? is in an illegal position.\n"; }
+ }
+}
diff --git a/challenge-194/jaldhar-h-vyas/raku/ch-2.raku b/challenge-194/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..f145836337
--- /dev/null
+++ b/challenge-194/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,20 @@
+#!/usr/bin/raku
+
+sub MAIN (
+ $s #= a string of alphabetic characters only
+) {
+ my @chars = $s.comb;
+ my $result = 0;
+
+ for 0 .. @chars.end -> $i {
+ my @others = @chars;
+ @others.splice($i, 1);
+ my %freq = @others.classify({ $_ }).map({ $_.key => $_.value.elems ;});
+ if [eq] %freq.values {
+ $result = 1;
+ last;
+ }
+ }
+
+ say $result;
+}