diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-12-06 18:50:07 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-12-06 18:50:07 +0000 |
| commit | 9bb39ef1eae0a14cc14bea1e07645e5c41f68a46 (patch) | |
| tree | 6e923873a3f32cf1531393b0ca7a05aa4133c8dc | |
| parent | 92e2c29a3c032377eff9c49dbdd4bded0ba5653e (diff) | |
| download | perlweeklychallenge-club-9bb39ef1eae0a14cc14bea1e07645e5c41f68a46.tar.gz perlweeklychallenge-club-9bb39ef1eae0a14cc14bea1e07645e5c41f68a46.tar.bz2 perlweeklychallenge-club-9bb39ef1eae0a14cc14bea1e07645e5c41f68a46.zip | |
- Added solutions by Robert DiCicco.
24 files changed, 2266 insertions, 1364 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 diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 40e7ebdb74..5a568f05b6 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,75 +1,4 @@ { - "series" : [ - { - "data" : [ - { - "y" : 2, - "name" : "Dave Jacoby", - "drilldown" : "Dave Jacoby" - }, - { - "drilldown" : "David Ferrone", - "y" : 2, - "name" : "David Ferrone" - }, - { - "name" : "Feng Chang", - "y" : 2, - "drilldown" : "Feng Chang" - }, - { - "y" : 3, - "name" : "James Smith", - "drilldown" : "James Smith" - }, - { - "drilldown" : "Luca Ferrari", - "y" : 8, - "name" : "Luca Ferrari" - }, - { - "y" : 2, - "name" : "Mark Anderson", - "drilldown" : "Mark Anderson" - }, - { - "name" : "Niels van Dijke", - "y" : 2, - "drilldown" : "Niels van Dijke" - }, - { - "y" : 2, - "name" : "Robbie Hatley", - "drilldown" : "Robbie Hatley" - }, - { - "y" : 4, - "name" : "Roger Bell_West", - "drilldown" : "Roger Bell_West" - }, - { - "drilldown" : "Vamsi Meenavilli", - "y" : 2, - "name" : "Vamsi Meenavilli" - }, - { - "name" : "W. Luis Mochan", - "y" : 3, - "drilldown" : "W. Luis Mochan" - } - ], - "colorByPoint" : 1, - "name" : "The Weekly Challenge - 194" - } - ], - "legend" : { - "enabled" : 0 - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, "drilldown" : { "series" : [ { @@ -117,6 +46,7 @@ "name" : "James Smith" }, { + "name" : "Luca Ferrari", "id" : "Luca Ferrari", "data" : [ [ @@ -127,8 +57,7 @@ "Blog", 6 ] - ], - "name" : "Luca Ferrari" + ] }, { "data" : [ @@ -141,14 +70,14 @@ "name" : "Mark Anderson" }, { - "name" : "Niels van Dijke", "data" : [ [ "Perl", 2 ] ], - "id" : "Niels van Dijke" + "id" : "Niels van Dijke", + "name" : "Niels van Dijke" }, { "name" : "Robbie Hatley", @@ -161,6 +90,20 @@ "id" : "Robbie Hatley" }, { + "name" : "Robert DiCicco", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Robert DiCicco" + }, + { "id" : "Roger Bell_West", "data" : [ [ @@ -175,16 +118,17 @@ "name" : "Roger Bell_West" }, { - "name" : "Vamsi Meenavilli", "data" : [ [ "Perl", 2 ] ], - "id" : "Vamsi Meenavilli" + "id" : "Vamsi Meenavilli", + "name" : "Vamsi Meenavilli" }, { + "name" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -195,35 +139,110 @@ 1 ] ], - "id" : "W. Luis Mochan", - "name" : "W. Luis Mochan" + "id" : "W. Luis Mochan" } ] }, - "subtitle" : { - "text" : "[Champions: 11] Last updated at 2022-12-06 17:46:43 GMT" - }, "tooltip" : { + "followPointer" : 1, "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", - "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", - "followPointer" : 1 - }, - "chart" : { - "type" : "column" + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>" }, + "series" : [ + { + "data" : [ + { + "drilldown" : "Dave Jacoby", + "y" : 2, + "name" : "Dave Jacoby" + }, + { + "name" : "David Ferrone", + "y" : 2, + "drilldown" : "David Ferrone" + }, + { + "name" : "Feng Chang", + "drilldown" : "Feng Chang", + "y" : 2 + }, + { + "name" : "James Smith", + "y" : 3, + "drilldown" : "James Smith" + }, + { + "drilldown" : "Luca Ferrari", + "y" : 8, + "name" : "Luca Ferrari" + }, + { + "drilldown" : "Mark Anderson", + "y" : 2, + "name" : "Mark Anderson" + }, + { + "drilldown" : "Niels van Dijke", + "y" : 2, + "name" : "Niels van Dijke" + }, + { + "drilldown" : "Robbie Hatley", + "y" : 2, + "name" : "Robbie Hatley" + }, + { + "name" : "Robert DiCicco", + "y" : 4, + "drilldown" : "Robert DiCicco" + }, + { + "drilldown" : "Roger Bell_West", + "y" : 4, + "name" : "Roger Bell_West" + }, + { + "y" : 2, + "drilldown" : "Vamsi Meenavilli", + "name" : "Vamsi Meenavilli" + }, + { + "name" : "W. Luis Mochan", + "drilldown" : "W. Luis Mochan", + "y" : 3 + } + ], + "colorByPoint" : 1, + "name" : "The Weekly Challenge - 194" + } + ], "xAxis" : { "type" : "category" }, + "legend" : { + "enabled" : 0 + }, + "subtitle" : { + "text" : "[Champions: 12] Last updated at 2022-12-06 18:44:36 GMT" + }, "plotOptions" : { "series" : { + "borderWidth" : 0, "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - }, - "borderWidth" : 0 + "format" : "{point.y}", + "enabled" : 1 + } } }, + "chart" : { + "type" : "column" + }, "title" : { "text" : "The Weekly Challenge - 194" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 026ce3a7b2..677071cbb6 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,10 +1,22 @@ { - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" + "subtitle" : { + "text" : "Last updated at 2022-12-06 18:44:36 GMT" + }, + "legend" : { + "enabled" : "false" + }, + "yAxis" : { + "min" : 0, + "title" : { + "text" : null + } }, "chart" : { "type" : "column" }, + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2022]" + }, < |
