aboutsummaryrefslogtreecommitdiff
path: root/challenge-194
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-12-06 18:50:07 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-12-06 18:50:07 +0000
commit9bb39ef1eae0a14cc14bea1e07645e5c41f68a46 (patch)
tree6e923873a3f32cf1531393b0ca7a05aa4133c8dc /challenge-194
parent92e2c29a3c032377eff9c49dbdd4bded0ba5653e (diff)
downloadperlweeklychallenge-club-9bb39ef1eae0a14cc14bea1e07645e5c41f68a46.tar.gz
perlweeklychallenge-club-9bb39ef1eae0a14cc14bea1e07645e5c41f68a46.tar.bz2
perlweeklychallenge-club-9bb39ef1eae0a14cc14bea1e07645e5c41f68a46.zip
- Added solutions by Robert DiCicco.
Diffstat (limited to 'challenge-194')
-rw-r--r--challenge-194/robert-dicicco/julia/ch-1.jl109
-rw-r--r--challenge-194/robert-dicicco/julia/ch-2.jl75
-rw-r--r--challenge-194/robert-dicicco/perl/ch-1.pl129
-rw-r--r--challenge-194/robert-dicicco/perl/ch-2.pl87
-rw-r--r--challenge-194/robert-dicicco/python/ch-1.py97
-rw-r--r--challenge-194/robert-dicicco/raku/ch-1.raku119
-rw-r--r--challenge-194/robert-dicicco/raku/ch-2.raku81
-rw-r--r--challenge-194/robert-dicicco/ruby/ch-1.rb101
-rw-r--r--challenge-194/robert-dicicco/ruby/ch-2.rb85
9 files changed, 883 insertions, 0 deletions
diff --git a/challenge-194/robert-dicicco/julia/ch-1.jl b/challenge-194/robert-dicicco/julia/ch-1.jl
new file mode 100644
index 0000000000..854aec54f5
--- /dev/null
+++ b/challenge-194/robert-dicicco/julia/ch-1.jl
@@ -0,0 +1,109 @@
+#!/usr/bin/env/julia
+
+#=
+
+AUTHOR: Robert DiCicco
+
+DATE: 2022-12-05
+
+Challenge 194 Digital Clock ( Julia )
+
+-------------------------------------------
+
+SAMPLE OUTPUT
+
+julia .\DigitalClock.jl
+
+Input: time = ?5:00
+
+Output: 1
+
+
+Input: time = ?3:00
+
+Output: 2
+
+
+Input: time = 1?:00
+
+Output: 9
+
+
+Input: time = 2?:00
+
+Output: 3
+
+
+Input: time = 12:?5
+
+Output: 5
+
+
+Input: time = 12:5?
+
+Output: 9
+
+=#
+
+
+using Printf
+
+
+templates = ["?5:00", "?3:00", "1?:00", "2?:00", "12:?5","12:5?"]
+
+
+function GetDigit(tp, n)
+
+ @printf("Input: time = %s\n",tp)
+
+ @printf("Output: ")
+
+ if (( n == 1 ) && (tp[2] < '4'))
+
+ @printf("2\n\n")
+
+ elseif (( n == 1 ) && (tp[2] >= '4' ))
+
+ @printf("1\n\n")
+
+ elseif (( n == 2 ) && (tp[1] <= '1'))
+
+ @printf("9\n\n")
+
+ elseif (( n == 2 ) && (tp[1] == '2'))
+
+ @printf("3\n\n")
+
+ elseif ( n == 4)
+
+ @printf("5\n\n")
+
+ elseif ( n == 5)
+
+ @printf("9\n\n")
+
+ else
+
+ println("Error!")
+
+ end
+
+end
+
+
+for tp in templates
+
+ ndx = findfirst("?", tp)[1]
+
+ GetDigit(tp,ndx);
+
+end
diff --git a/challenge-194/robert-dicicco/julia/ch-2.jl b/challenge-194/robert-dicicco/julia/ch-2.jl
new file mode 100644
index 0000000000..68c1c7ed00
--- /dev/null
+++ b/challenge-194/robert-dicicco/julia/ch-2.jl
@@ -0,0 +1,75 @@
+#!/usr/bin/env julia
+
+#=
+
+AUTHOR: Robert DiCicco
+
+DATE: 2022-12-06
+
+Challenge 194 Frequency Equalizer ( Julia )
+
+
+SAMPLE OUTPUT
+
+julia .\FrequencyEqualizer.jl
+
+Input: $s = 'abbc'
+
+Output: 1
+
+
+Input: $s = 'xyzyyxz'
+
+Output: 1
+
+
+Input: $s = 'xzxz'
+
+Output: 0
+
+=#
+
+using Printf
+
+
+ss = ["abbc", "xyzyyxz", "xzxz"]
+
+x = 1
+
+
+for s in ss
+
+ global x
+
+ seen = Dict()
+
+ @printf("Input: \$s = \'%s\'\n", s)
+
+ ln = length(s)
+
+ while x <= ln
+
+ zsub = SubString(s,x,x);
+
+ haskey(seen,zsub) ? seen[zsub] += 1 : seen[zsub] = 1
+
+ x += 1
+
+ end
+
+ highest = maximum(values(seen))
+
+ lowest = minimum(values(seen))
+
+ lowest + 1 == highest ? println("Output: 1\n") : println("Output: 0\n")
+
+ x = 1
+
+end
+
diff --git a/challenge-194/robert-dicicco/perl/ch-1.pl b/challenge-194/robert-dicicco/perl/ch-1.pl
new file mode 100644
index 0000000000..7b157f8f74
--- /dev/null
+++ b/challenge-194/robert-dicicco/perl/ch-1.pl
@@ -0,0 +1,129 @@
+#!/usr/bin/env perl
+
+=begin pod
+
+AUTHOR: Robert DiCicco
+
+DATE: 2022-12-05
+
+Challenge 194 Digital Clock ( Perl )
+
+-------------------------------------------
+
+SAMPLE OUTPUT
+
+perl .\DigitalClock.pl
+
+Input: $time = '?5:00'
+
+Output: 1
+
+
+Input: $time = '?3:00'
+
+Output: 2
+
+
+Input: $time = '1?:00'
+
+Output: 9
+
+
+Input: $time = '2?:00'
+
+Output: 3
+
+
+Input: $time = '12:?5'
+
+Output: 5
+
+
+Input: $time = '12:5?'
+
+Output: 9
+
+-------------------------------------------
+
+=cut
+
+
+use strict;
+
+use warnings;
+
+use feature qw/say/;
+
+
+my @templates = ('?5:00', '?3:00', '1?:00', '2?:00', '12:?5','12:5?');
+
+
+sub GetDigit {
+
+ my $tp = shift;
+
+ my $n = shift;
+
+ print "Input: \$time = \'$tp\'\n";
+
+ print "Output: ";
+
+ if (( $n == 0 ) && (substr($tp,1,1) < '4')){
+
+ say "2";
+
+ }
+
+ elsif (( $n == 0 ) && (substr($tp,1,1) >= '4' )){
+
+ say "1";
+
+ }
+
+ elsif (($n == 1) && (substr($tp,0,1) <= '1')) {
+
+ say "9";
+
+ }
+
+ elsif (($n == 1) && (substr($tp,0,1) == '2')) {
+
+ say "3";
+
+ }
+
+ elsif ($n == 3) {
+
+ say "5";
+
+ }
+
+ elsif ($n == 4) {
+
+ say "9";
+
+ }
+
+ else {die "Error!"};
+
+ say " ";
+
+ }
+
+
+for my $tp (@templates) {
+
+ my $ndx = index($tp,'?');
+
+ GetDigit($tp,$ndx);
+
+}
diff --git a/challenge-194/robert-dicicco/perl/ch-2.pl b/challenge-194/robert-dicicco/perl/ch-2.pl
new file mode 100644
index 0000000000..98628f3e1a
--- /dev/null
+++ b/challenge-194/robert-dicicco/perl/ch-2.pl
@@ -0,0 +1,87 @@
+#!/usr/bin/env perl
+
+=begin pod
+
+AUTHOR: Robert DiCicco
+
+DATE: 2022-12-06
+
+Challenge 194 Frequency Equalizer ( Perl )
+
+------------------------------
+
+SAMPLE OUTPUT
+
+ perl .\FrequencyEqualizer.pl
+
+Input: $s = abbc
+
+Output: 1
+
+------------------------------
+
+Input: $s = xyzyyxz
+
+Output: 1
+
+------------------------------
+
+Input: $s = xzxz
+
+Output: 0
+
+------------------------------
+
+=cut
+
+use strict;
+
+use warnings;
+
+use feature qw/say/;
+
+use List::UtilsBy qw(max_by min_by);
+
+
+my %seen = ();
+
+
+my @ss = (("abbc"), ("xyzyyxz"), ("xzxz"));
+
+my $x = 0;
+
+
+foreach my $s (@ss) {
+
+ say "Input: \$s = $s";
+
+ my $ln = length($s);
+
+ while( $x < $ln ) {
+
+ my $zsub = substr($s,$x,1);
+
+ $seen{$zsub} += 1;
+
+ if ($x < $ln) {$x++};
+
+ }
+
+ my $highest = max_by { $seen{$_} } keys %seen;
+
+ my $lowest = min_by { $seen{$_} } keys %seen;
+
+
+ ($seen{$lowest} + 1 == $seen{$highest}) ? say "Output: 1" : say "Output: 0";
+
+ say "------------------------------";
+
+ $x = 0;
+
+ %seen = ();
+
+}
diff --git a/challenge-194/robert-dicicco/python/ch-1.py b/challenge-194/robert-dicicco/python/ch-1.py
new file mode 100644
index 0000000000..74bb343b88
--- /dev/null
+++ b/challenge-194/robert-dicicco/python/ch-1.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python
+
+'''
+
+AUTHOR: Robert DiCicco
+
+DATE: 2022-12-05
+
+Challenge 194 Digital Clock ( Python )
+
+-------------------------------------------
+
+SAMPLE OUTPUT
+
+python .\DigitalClock.py
+
+Input: $time = '?5:00'
+
+Output: 1
+
+
+Input: $time = '?3:00'
+
+Output: 2
+
+
+Input: $time = '1?:00'
+
+Output: 9
+
+
+Input: $time = '2?:00'
+
+Output: 3
+
+
+Input: $time = '12:?5'
+
+Output: 5
+
+
+Input: $time = '12:5?'
+
+Output: 9
+
+'''
+
+
+templates = ["?5:00", "?3:00", "1?:00", "2?:00", "12:?5","12:5?"]
+
+
+def GetDigit(tp, n) :
+
+ print(f"Input: $time = '{tp}'")
+
+ print("Output: ", end = " ")
+
+ if (( n == 0 ) and (tp[1] < '4')) :
+
+ print("2\n")
+
+ elif (( n == 0 ) and (tp[1] >= '4' )) :
+
+ print("1\n")
+
+ elif (( n == 1 ) and (tp[0] <= '1')) :
+
+ print("9\n")
+
+ elif (( n == 1 ) and (tp[0] == '2')) :
+
+ print("3\n")
+
+ elif ( n == 3) :
+
+ print("5\n")
+
+ elif ( n == 4) :
+
+ print("9\n")
+
+ else :
+
+ print("Error!")
+
+
+for tp in templates :
+
+ GetDigit(tp,tp.index('?'))
diff --git a/challenge-194/robert-dicicco/raku/ch-1.raku b/challenge-194/robert-dicicco/raku/ch-1.raku
new file mode 100644
index 0000000000..3e1f54e767
--- /dev/null
+++ b/challenge-194/robert-dicicco/raku/ch-1.raku
@@ -0,0 +1,119 @@
+#!/usr/bin/env raku
+
+=begin comment
+
+AUTHOR: Robert DiCicco
+
+DATE: 2022-12-05
+
+Challenge 194 Digital Clock ( Raku )
+
+-------------------------------------------
+
+SAMPLE OUTPUT
+
+raku .\DigitalClock.rk
+
+Input: $time = '?5:00'
+
+Output: 1
+
+
+Input: $time = '?3:00'
+
+Output: 2
+
+
+Input: $time = '1?:00'
+
+Output: 9
+
+
+Input: $time = '2?:00'
+
+Output: 3
+
+
+Input: $time = '12:?5'
+
+Output: 5
+
+
+Input: $time = '12:5?'
+
+Output: 9
+
+=end comment
+
+
+use v6;
+
+
+my @templates = ('?5:00', '?3:00', '1?:00', '2?:00', '12:?5','12:5?');
+
+
+sub GetDigit($tp, $n) {
+
+ print "Input: \$time = \'$tp\'\n";
+
+ print "Output: ";
+
+ if (( $n == 0 ) && (substr($tp,1,1) < '4')) {
+
+ say "2";
+
+ }
+
+ elsif (( $n == 0 ) && (substr($tp,1,1) >= '4' )) {
+
+ say "1";
+
+ }
+
+ elsif (($n == 1) && (substr($tp,0,1) <= '1')) {
+
+ say "9";
+
+ }
+
+ elsif (($n == 1) && (substr($tp,0,1) == '2')) {
+
+ say "3";
+
+ }
+
+ elsif ($n == 3) {
+
+ say "5";
+
+ }
+
+ elsif ($n == 4) {
+
+ say "9";
+
+ }
+
+ else {die "Error!"};
+
+ say " ";
+
+}
+
+
+for @templates -> $tp {
+
+ #say $tp;
+
+ GetDigit($tp,$tp.index('?'));
+
+}
diff --git a/challenge-194/robert-dicicco/raku/ch-2.raku b/challenge-194/robert-dicicco/raku/ch-2.raku
new file mode 100644
index 0000000000..436308d5a5
--- /dev/null
+++ b/challenge-194/robert-dicicco/raku/ch-2.raku
@@ -0,0 +1,81 @@
+#!/usr/bin/env raku
+
+#`{
+
+AUTHOR: Robert DiCicco
+
+DATE: 2022-12-06
+
+Challenge 194 Frequency Equalizer ( Raku )
+
+SAMPLE OUTPUT
+
+raku .\FrequencyEqualizer.rk
+
+Input: $s = 'abbc'
+
+Output: 1
+
+
+Input: $s = 'xyzyyxz'
+
+Output: 1
+
+
+Input: $s = 'xzxz'
+
+Output: 0
+
+}
+
+
+use v6;
+
+use List::UtilsBy qw/max_by min_by/;
+
+
+my @ss = ("abbc", "xyzyyxz", "xzxz");
+
+my $x = 0;
+
+my %seen = ();
+
+
+for (@ss) -> $s {
+
+ say "Input: \$s = \'$s\'";
+
+ my $ln = $s.chars;
+
+ while $x < $ln {
+
+ my $zsub = substr($s,$x,1);
+
+ %seen{$zsub} += 1;
+
+ if ($x < $ln) {$x++};
+
+ my $highest = max()
+
+ }
+
+ my $highest = max_by Scalar, { %seen{$_}}, keys %seen;
+
+ my $lowest = min_by Scalar, { %seen{$_}}, keys %seen;
+
+
+ (%seen{$lowest} + 1 == %seen{$highest}) ?? say "Output: 1\n" !! say "Output: 0\n";
+
+
+ $x = 0;
+
+ %seen = ();
+
+}
diff --git a/challenge-194/robert-dicicco/ruby/ch-1.rb b/challenge-194/robert-dicicco/ruby/ch-1.rb
new file mode 100644
index 0000000000..60fa167e43
--- /dev/null
+++ b/challenge-194/robert-dicicco/ruby/ch-1.rb
@@ -0,0 +1,101 @@
+#!/usr/bin/env ruby
+
+=begin
+
+AUTHOR: Robert DiCicco
+
+DATE: 2022-12-05
+
+Challenge 194 Digital Clock ( Ruby )
+
+-------------------------------------------
+
+SAMPLE OUTPUT
+
+ruby .\DigitalClock.rb
+
+Input: time = ?5:00
+
+Output: 1
+
+
+Input: time = ?3:00
+
+Output: 2
+
+
+Input: time = 1?:00
+
+Output: 9
+
+
+Input: time = 2?:00
+
+Output: 3
+
+
+Input: time = 12:?5
+
+Output: 5
+
+
+Input: time = 12:5?
+
+Output: 9
+
+=end
+
+templates = ['?5:00', '?3:00', '1?:00', '2?:00', '12:?5','12:5?'];
+
+
+def GetDigit(tp, n)
+
+ puts("Input: time = #{tp}")
+
+ print "Output: "
+
+ if (( n == 0 ) && (tp[1,1] < '4'))
+
+ printf "2\n\n"
+
+ elsif (( n == 0 ) && (tp[1,1] >= '4' ))
+
+ printf "1\n\n"
+
+ elsif (( n == 1 ) && (tp[0,1] <= '1'))
+
+ printf "9\n\n"
+
+ elsif (( n == 1 ) && (tp[0,1] == '2'))
+
+ printf "3\n\n"
+
+ elsif ( n == 3)
+
+ printf "5\n\n"
+
+ elsif ( n == 4)
+
+ printf "9\n\n";
+
+ else
+
+ puts "Error!";
+
+ end
+
+end
+
+
+templates.each do |tp|
+
+ GetDigit(tp,tp.index('?'));
+
+end
diff --git a/challenge-194/robert-dicicco/ruby/ch-2.rb b/challenge-194/robert-dicicco/ruby/ch-2.rb
new file mode 100644
index 0000000000..38121e7102
--- /dev/null
+++ b/challenge-194/robert-dicicco/ruby/ch-2.rb
@@ -0,0 +1,85 @@
+#!/usr/bin/env ruby
+
+=begin
+
+AUTHOR: Robert DiCicco
+
+DATE: 2022-12-06
+
+Challenge 194 Frequency Equalizer ( Ruby )
+
+
+SAMPLE OUTPUT
+
+ruby .\FrequencyEqualizer.rb
+
+Input: $s = 'abbc'
+
+Output: 1
+
+
+Input: $s = 'xyzyyxz'
+
+Output: 1
+
+
+Input: $s = 'xzxz'
+
+Output: 0
+
+=end
+
+
+ss = ["abbc", "xyzyyxz", "xzxz"]
+
+x = 0
+
+seen = Hash.new
+
+
+ss.each do |s|
+
+ puts("Input: $s = \'#{s}\'")
+
+ ln = s.length;
+
+ while x < ln
+
+ zsub = s[x,1]
+
+ if seen.key?(zsub)
+
+ seen[zsub] += 1
+
+ else
+
+ seen[zsub] = 1
+
+ end
+
+ if (x < ln)
+
+ x += 1
+
+ end
+
+ end
+
+ highest = seen.values.max
+
+ lowest = seen.values.min
+
+ lowest + 1 == highest ? puts("Output: 1") : puts("Output: 0")
+
+ puts(" ")
+
+ seen = Hash.new
+
+ x = 0
+
+end