aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Lynn <bizlsg@localhost.localdomain>2022-12-08 19:33:12 +0800
committerStephen Lynn <bizlsg@localhost.localdomain>2022-12-08 19:33:12 +0800
commitf92b7873bbf273d639c66ed8a207f51816847d27 (patch)
tree176ff11b594d658e89af485cc1dcc7da91185e53
parent14e3c6a41685893e9a7a830d98fabe069bc4d0b5 (diff)
downloadperlweeklychallenge-club-f92b7873bbf273d639c66ed8a207f51816847d27.tar.gz
perlweeklychallenge-club-f92b7873bbf273d639c66ed8a207f51816847d27.tar.bz2
perlweeklychallenge-club-f92b7873bbf273d639c66ed8a207f51816847d27.zip
pwc 194
-rw-r--r--challenge-194/steve-g-lynn/blog.txt1
-rwxr-xr-xchallenge-194/steve-g-lynn/perl/ch-1.pl64
-rwxr-xr-xchallenge-194/steve-g-lynn/perl/ch-2.pl35
-rwxr-xr-xchallenge-194/steve-g-lynn/raku/ch-1.p666
-rwxr-xr-xchallenge-194/steve-g-lynn/raku/ch-2.p628
5 files changed, 194 insertions, 0 deletions
diff --git a/challenge-194/steve-g-lynn/blog.txt b/challenge-194/steve-g-lynn/blog.txt
new file mode 100644
index 0000000000..c1aad4013f
--- /dev/null
+++ b/challenge-194/steve-g-lynn/blog.txt
@@ -0,0 +1 @@
+https://thiujiac.blogspot.com/2022/12/pwc-194.html
diff --git a/challenge-194/steve-g-lynn/perl/ch-1.pl b/challenge-194/steve-g-lynn/perl/ch-1.pl
new file mode 100755
index 0000000000..a7ce0d8a3c
--- /dev/null
+++ b/challenge-194/steve-g-lynn/perl/ch-1.pl
@@ -0,0 +1,64 @@
+#!/usr/bin/env perl
+
+print &digital_clock('?5:00'),"\n"; #1
+print &digital_clock('?3:00'),"\n"; #2
+print &digital_clock('1?:00'),"\n"; #9
+print &digital_clock('2?:00'),"\n"; #3
+print &digital_clock('12:?5'),"\n"; #5
+print &digital_clock('12:5?'),"\n"; #9
+
+sub digital_clock {
+ my ($time)=@_;
+
+ $time =~ /^[0-2?][0-9?]:[0-5?][0-9?]$/ || (return "Invalid input");
+ (substr($time,0,2) >= 24) && (return "Invalid input");
+ (substr($time,3,2) > 59) && (return "Invalid input");
+
+ my @time=split(//,$time);
+ my (%i, %time_indx, $ctr);
+
+ $ctr=0;
+
+ for my $i (@time){
+ $i{$i}++;
+ $time_indx{$i}=$ctr++;
+ }
+
+ (return "Invalid input") unless ($i{'?'}==1);
+
+ if ($time_indx{'?'}==0) {
+ if ($time[1] > 3) {
+ return 1;
+ }
+ else {
+ return 2;
+ }
+ }
+
+ if ($time_indx{'?'}==1) {
+ if ($time[0] <= 1) {
+ return 9;
+ }
+ elsif ($time[0] == 2) {
+ return 3;
+ }
+ else { #-- shouldn't get here
+ return "Something wrong";
+ }
+ }
+
+ if ($time_indx{'?'}==2) { #-- shouldn't get here
+ return "Something wrong";
+ }
+
+ if ($time_indx{'?'}==3) {
+ return 5;
+ }
+
+ if ($time_indx{'?'}==4) {
+ return 9;
+ }
+
+}
+
+
diff --git a/challenge-194/steve-g-lynn/perl/ch-2.pl b/challenge-194/steve-g-lynn/perl/ch-2.pl
new file mode 100755
index 0000000000..72bc6baa55
--- /dev/null
+++ b/challenge-194/steve-g-lynn/perl/ch-2.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use List::Util qw(min max);
+
+print frequency_equalizer('abbc'),"\n"; #1
+print frequency_equalizer('xyzyyxz'),"\n"; #1
+print frequency_equalizer('xzxz'),"\n"; #0
+
+
+sub frequency_equalizer {
+ my ($s) = @_;
+
+ my @s = split (//, $s);
+
+ my (%s, %uniq);
+
+ for my $i (@s) {
+ $s{$i}++;
+ }
+
+ for my $i (values %s) {
+ $uniq{$i} = $i;
+ }
+
+ @s = sort keys %uniq;
+
+ ( (scalar(@s)==2) && (min(@s)==(max(@s)-1)) ) &&
+ (return 1);
+
+ return 0;
+}
+
diff --git a/challenge-194/steve-g-lynn/raku/ch-1.p6 b/challenge-194/steve-g-lynn/raku/ch-1.p6
new file mode 100755
index 0000000000..6e0d9f0e84
--- /dev/null
+++ b/challenge-194/steve-g-lynn/raku/ch-1.p6
@@ -0,0 +1,66 @@
+#!/usr/bin/env perl6
+
+say &digital-clock('?5:00'); #1
+say &digital-clock('?3:00'); #2
+say &digital-clock('1?:00'); #9
+say &digital-clock('2?:00'); #3
+say &digital-clock('12:?5'); #5
+say &digital-clock('12:5?'); #9
+
+sub digital-clock (Str $time) {
+
+ $time ~~ /^ <[0 .. 2 ?]> <[0 .. 9 ?]> \: <[0 .. 5 ?]> <[0 .. 9 ?]>$/ || (return "Invalid input");
+
+ ($time ~~ /\?/) || (return "Invalid input");
+
+ ( (substr($time,0,2) ~~ /^ <[0 .. 2]> <[0 .. 9]> $/) && (substr($time,0,2) > 23) ) && (return "Invalid input");
+
+ ( (substr($time,3,2) ~~ /^ <[0 .. 5]> <[0 .. 9]> $/) && (substr($time,3,2) > 59) ) && (return "Invalid input");
+
+ my @time=$time.comb;
+ my (%i, %time_indx, $ctr);
+
+ $ctr=0;
+
+ for (@time) -> $i {
+ %i{$i}++;
+ %time_indx{$i}=$ctr++;
+ }
+
+ (return "Invalid input") unless (%i{'?'}==1);
+
+ if (%time_indx{'?'}==0) {
+ if (@time[1] > 3) {
+ return 1;
+ }
+ else {
+ return 2;
+ }
+ }
+
+ if (%time_indx{'?'}==1) {
+ if (@time[0] <= 1) {
+ return 9;
+ }
+ elsif (@time[0] == 2) {
+ return 3;
+ }
+ else { #-- shouldn't get here
+ return "Something wrong";
+ }
+ }
+
+ if (%time_indx{'?'}==2) { #-- shouldn't get here
+ return "Something wrong";
+ }
+
+ if (%time_indx{'?'}==3) {
+ return 5;
+ }
+
+ if (%time_indx{'?'}==4) {
+ return 9;
+ }
+}
+
+
diff --git a/challenge-194/steve-g-lynn/raku/ch-2.p6 b/challenge-194/steve-g-lynn/raku/ch-2.p6
new file mode 100755
index 0000000000..595f4fbcfc
--- /dev/null
+++ b/challenge-194/steve-g-lynn/raku/ch-2.p6
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl6
+
+say frequency-equalizer('abbc'); #1
+say frequency-equalizer('xyzyyxz'); #1
+say frequency-equalizer('xzxz'); #0
+
+sub frequency-equalizer( Str $s ) {
+
+ my @s = $s.comb;
+
+ my (%s, %uniq);
+
+ for (@s) -> $i {
+ %s{$i}++;
+ }
+
+ for (%s.values) -> $i {
+ %uniq{$i} = $i;
+ }
+
+ @s = %uniq.keys.sort;
+
+ ( ( @s.elems == 2 ) && (@s.min==(@s.max-1)) ) &&
+ (return 1);
+
+ return 0;
+}
+