diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-11-22 19:16:57 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-11-22 19:16:57 +0000 |
| commit | b63eb01f6936c623baf9ee7d0d8303b549d62c7d (patch) | |
| tree | a7431af68753d8c35120e9755cc2383d10c95b50 | |
| parent | bafffe33c0839de0c554cb27f1ffe562429cc882 (diff) | |
| download | perlweeklychallenge-club-b63eb01f6936c623baf9ee7d0d8303b549d62c7d.tar.gz perlweeklychallenge-club-b63eb01f6936c623baf9ee7d0d8303b549d62c7d.tar.bz2 perlweeklychallenge-club-b63eb01f6936c623baf9ee7d0d8303b549d62c7d.zip | |
- Added solutions by Robert DiCicco.
| -rw-r--r-- | challenge-192/robert-dicicco/julia/ch-1.jl | 101 | ||||
| -rw-r--r-- | challenge-192/robert-dicicco/perl/ch-1.pl | 99 | ||||
| -rw-r--r-- | challenge-192/robert-dicicco/perl/ch-2.pl | 225 | ||||
| -rw-r--r-- | challenge-192/robert-dicicco/raku/ch-1.raku | 91 | ||||
| -rw-r--r-- | challenge-192/robert-dicicco/ruby/ch-1.rb | 109 | ||||
| -rw-r--r-- | challenge-192/robert-dicicco/tcl/ch-1.tcl | 107 | ||||
| -rw-r--r-- | stats/pwc-current.json | 139 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 56 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 2622 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 720 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 38 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 106 | ||||
| -rw-r--r-- | stats/pwc-summary-151-180.json | 34 | ||||
| -rw-r--r-- | stats/pwc-summary-181-210.json | 116 | ||||
| -rw-r--r-- | stats/pwc-summary-211-240.json | 40 | ||||
| -rw-r--r-- | stats/pwc-summary-241-270.json | 118 | ||||
| -rw-r--r-- | stats/pwc-summary-271-300.json | 46 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 46 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 96 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 44 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 50 |
21 files changed, 2877 insertions, 2126 deletions
diff --git a/challenge-192/robert-dicicco/julia/ch-1.jl b/challenge-192/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..031e296602 --- /dev/null +++ b/challenge-192/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,101 @@ +#!/usr/bin/env julia + +#= + +AUTHOR: Robert DiCicco + + DATE: 2022-11-21 + + Challenge 192 Binary Flip ( Julia ) + + + + You are given a positive integer, $n. + + + + Write a script to find the binary flip. + + Example 1 + + + + Input: $n = 5 + + Output: 2 + + + + First find the binary equivalent of the given integer, 101. + + Then flip the binary digits 0 -> 1 and 1 -> 0 and we get 010. + + So Binary 010 => Decimal 2. + +=# + + + +using Printf + +using Match + + + +ns = [5,4,6] + + + +for n in ns + + out = [] + + @printf("\nInput: \$n = %d\n", n) + + binvals=string(n, base=2) + + for character in binvals + + @match character begin + + '1' => push!(out,'0') + + '0' => push!(out,'1') + + _ => println("Something else...") + + end + + end + + println(parse(Int, join(out); base=2)) + +end + + + +#= + +SAMPLE OUTPUT + +julia .\BinaryFlip.jl + + + +Input: $n = 5 + +2 + + + +Input: $n = 4 + +3 + + + +Input: $n = 6 + +1 + +=# diff --git a/challenge-192/robert-dicicco/perl/ch-1.pl b/challenge-192/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..d8e302e113 --- /dev/null +++ b/challenge-192/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,99 @@ +#!/usr/bin/env perl + +=begin pod + +AUTHOR: Robert DiCicco + +DATE: 2022-11-21 + +Challenge 192 Binary Flip ( Perl ) + + + +You are given a positive integer, $n. + + + +Write a script to find the binary flip. + +Example 1 + + + +Input: $n = 5 + +Output: 2 + + + +First find the binary equivalent of the given integer, 101. + +Then flip the binary digits 0 -> 1 and 1 -> 0 and we get 010. + +So Binary 010 => Decimal 2. + +=cut + + + +use strict; + +use warnings; + + + +my @ns = (5,4,6); + + + +sub bin2dec { + + return unpack("N", pack("B32", substr("0" x 32 . shift, -32))); + +} + + + +for my $n (@ns) { + + my @out = (); + + my @binvals = split("",sprintf("%03b", $n) ); + + for my $v (@binvals) { + + $v == 0 ? push(@out,1) : push(@out,0); + + } + + my $outval = join("", @out); + + my $retval = bin2dec($outval); + + print "Input: \$n = $n\n"; + + print "Output: $retval\n\n"; + +} + + + +=begin pod + +Input: $n = 5 + +Output: 2 + + + +Input: $n = 4 + +Output: 3 + + + +Input: $n = 6 + +Output: 1 + +=cut diff --git a/challenge-192/robert-dicicco/perl/ch-2.pl b/challenge-192/robert-dicicco/perl/ch-2.pl new file mode 100644 index 0000000000..8bc3a7a940 --- /dev/null +++ b/challenge-192/robert-dicicco/perl/ch-2.pl @@ -0,0 +1,225 @@ +#!/usr/bin/env perl + +=begin pod + +AUTHOR: Robert DiCicco + +DATE: 2022-11-22 + +Challenge 192 Equal Distribution ( Perl ) + + + +You are given a list of integers greater than or equal to zero, @list. + + + +Write a script to distribute the number so that each members are same. If you succeed then print the total moves otherwise print -1. + + + +Please follow the rules (as suggested by Neils van Dijke [2022-11-21 13:00] + + + +1) You can only move a value of '1' per move + +2) You are only allowed to move a value of '1' to a direct neighbor/adjacent cell + + + +SAMPLE OUTPUT + +perl .\EqualDistribution.pl + +Input: @lst = (1 0 5) + + 1 1 4 + + 1 2 3 + + 1 3 2 + + 2 2 2 + +Output: 4 + + + +Input: @lst = (0 2 0) + +Output: -1 + + + +Input: @lst = (0 3 0) + + 1 2 0 + + 1 1 1 + +Output: 2 + +output + +perl .\EqualDistribution.pl + +Input: @lst = (1 0 5) + + 1 1 4 + + 1 2 3 + + 1 3 2 + + 2 2 2 + +Output: 4 + + + +Input: @lst = (0 2 0) + +Output: -1 + + + +Input: @lst = (0 3 0) + + 1 2 0 + + 1 1 1 + +Output: 2 + + + +=cut + + + +use strict; + +use warnings; + +use feature qw/say/; + +use signatures; + + + +my @list = ([1,0,5], [0,2,0], [0,3,0]); + +my $cnt; + + + +sub MaxPos( $arr ) { + + my $max = 0; + + my $maxpos = -1; + + for (my $x=0; $x < 3; $x++) { + + if (@$arr[$x] > $max) { + + $max = @$arr[$x]; + + $maxpos = $x; + + } + + } + + return $max, $maxpos; + +} + + + +sub MinPos( $arr ) { + + my $min = 9; + + my $minpos = -1; + + for (my $x=0; $x < 3; $x++) { + + if (@$arr[$x] < $min) { + + $min = @$arr[$x]; + + $minpos = $x; + + } + + } + + return $min, $minpos; + +} + + + +sub EvenUp( $arr) { + + $cnt++; + + my ($max, $maxpos) = MaxPos($arr); + + my ($min, $minpos) = MinPos($arr); + + say "\t@$arr" if ($cnt > 1); + + @$arr[$maxpos]--; + + ($maxpos == 0) || ($maxpos == 2) ? @$arr[1]++ : @$arr[$minpos]++; + + if ((@$arr[0] == @$arr[1] == @$arr[2])) { + + say "\t@$arr"; + + say "Output: $cnt"; + + say " "; + + } else { + + EvenUp($arr); + + } + +} + + + +sub GetTotalVal($arr) { + + my $sum = 0; + + foreach my $i (0 .. 2) + + { + + $sum += @$arr[$i]; + + } + + return $sum + +} + + + +for my $lst (@list) { + + say "Input: \@lst = (@$lst)"; + + $cnt = 0; + + my $target = (GetTotalVal($lst) / 3); + + $target >= 1 ? EvenUp($lst) : say "Output: -1\n"; + +} diff --git a/challenge-192/robert-dicicco/raku/ch-1.raku b/challenge-192/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..94261b1cf9 --- /dev/null +++ b/challenge-192/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,91 @@ +use v6; + +#`{ + + AUTHOR: Robert DiCicco + + DATE: 2022-11-21 + + Challenge 192 Binary Flip ( Raku ) + + + + You are given a positive integer, $n. + + + + Write a script to find the binary flip. + + Example 1 + + + + Input: $n = 5 + + Output: 2 + + + + First find the binary equivalent of the given integer, 101. + + Then flip the binary digits 0 -> 1 and 1 -> 0 and we get 010. + + So Binary 010 => Decimal 2. + +} + + + +my @ns = (5,4,6); + + + +for @ns -> $n { + + my @out = (); + + say "Input: \$n = $n"; + + my @binvals = split("",sprintf("%03b", $n) ); + + for @binvals[1..3] -> $v { + + $v == 0 ?? @out.push(1) !! @out.push(0); + + } + + my $outj = @out.join; + + my $intval = ":2<$outj>".Int; + + say "Output: $intval\n"; + +} + + + +#`{ + + SAMPLE Output + + raku .\BinaryFlip.rk + + + + Input: $n = 5 + + Output: 2 + + + + Input: $n = 4 + + Output: 3 + + + + Input: $n = 6 + + Output: 1 + +} diff --git a/challenge-192/robert-dicicco/ruby/ch-1.rb b/challenge-192/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..651426a322 --- /dev/null +++ b/challenge-192/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,109 @@ +#!/usr/bin/env ruby + +=begin + + AUTHOR: Robert DiCicco + + DATE: 2022-11-21 + + Challenge 192 Binary Flip ( Ruby ) + + + + You are given a positive integer, $n. + + + + Write a script to find the binary flip. + + Example 1 + + + + Input: $n = 5 + + Output: 2 + + + + First find the binary equivalent of the given integer, 101. + + Then flip the binary digits 0 -> 1 and 1 -> 0 and we get 010. + + So Binary 010 => Decimal 2. + + + +=end + + + +ns = [5,4,6]; + + + +ns.each do |n| + + out = [] + + binvals = [] + + puts "Input: $n = #{n}" + + binvals = sprintf("%B", n).to_s + + (0..2).each do |v| + + if binvals[v] == '0' + + out.push('1') + + elsif binvals[v] == '1' + + out.push('0') + + else + + next + + end + + end + + puts "Output: #{out.join.to_i(2)}" + + puts " " + +end + + + +=begin + +SAMPLE OUTPUT + + + +ruby .\BinaryFlip.rb + + + +Input: $n = 5 + +Output: 2 + + + +Input: $n = 4 + +Output: 3 + + + +Input: $n = 6 + +Output: 1 + + + +=end diff --git a/challenge-192/robert-dicicco/tcl/ch-1.tcl b/challenge-192/robert-dicicco/tcl/ch-1.tcl new file mode 100644 index 0000000000..63ceb889f2 --- /dev/null +++ b/challenge-192/robert-dicicco/tcl/ch-1.tcl @@ -0,0 +1,107 @@ +#!/usr/bin/env tclsh + + + +set comment { + + AUTHOR: Robert DiCicco + + DATE: 2022-11-21 + + Challenge 192 Binary Flip ( Tcl ) + + + + You are given a positive integer, $n. + + + + Write a script to find the binary flip. + + Example 1 + + + + Input: $n = 5 + + Output: 2 + + + + First find the binary equivalent of the given integer, 101. + + Then flip the binary digits 0 -> 1 and 1 -> 0 and we get 010. + + So Binary 010 => Decimal 2. + +} + + + +set arr { 5 4 6 } + + + +proc dec2bin int { + + set binRep [binary format c $int] + + binary scan $binRep B* binStr + + return [string trimleft $binStr 0] + +} + + + +foreach n $arr { + + set out {} + + puts "Input: \$n = $n" + + set retval [ dec2bin $n] + + foreach char [split $retval ""] { + + if {$char == "1"} { lappend out "0"} else { lappend out "1"} + + } + + set stripped [string map {" " ""} $out] + + set dec [expr "0b$stripped"] + + puts "Output: $dec\n" + +} + + + +set comment { + +SAMPLE OUTPUT + + + +tclsh .\BinaryFlip.tcl + +Input: $n = 5 + +Output: 2 + + + +Input: $n = 4 + +Output: 3 + + + +Input: $n = 6 + +Output: 1 + + + +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index e80ccb92c6..eebea3b9a4 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,9 +1,14 @@ { - "title" : { - "text" : "The Weekly Challenge - 192" + "chart" : { + "type" : "column" }, - "legend" : { - "enabled" : 0 + "xAxis" : { + "type" : "category" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } }, "drilldown" : { "series" : [ @@ -18,27 +23,26 @@ "id" : "Dario Mazzeo" }, { - "id" : "E. Choroba", "data" : [ [ "Perl", 2 ] ], - "name" : "E. Choroba" + "name" : "E. Choroba", + "id" : "E. Choroba" }, { + "id" : "Humberto Massa", "name" : "Humberto Massa", "data" : [ [ "Raku", 2 ] - ], - "id" : "Humberto Massa" + ] }, { - "id" : "James Smith", "data" : [ [ "Perl", @@ -49,7 +53,8 @@ 1 ] ], - "name" : "James Smith" + "name" : "James Smith", + "id" : "James Smith" }, { "id" : "Mark Anderson", @@ -62,23 +67,23 @@ "name" : "Mark Anderson" }, { - "name" : "Niels van Dijke", "data" : [ [ "Perl", 2 ] ], + "name" : "Niels van Dijke", "id" : "Niels van Dijke" }, { - "name" : "Olivier Delouya", "data" : [ [ "Perl", 1 ] ], + "name" : "Olivier Delouya", "id" : "Olivier Delouya" }, { @@ -92,18 +97,32 @@ 1 ] ], - "id" : "Peter Campbell Smith", - "name" : "Peter Campbell Smith" + "name" : "Peter Campbell Smith", + "id" : "Peter Campbell Smith" }, { "id" : "Robbie Hatley", + "name" : "Robbie Hatley", "data" : [ [ "Perl", 2 ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 1 + ] ], - "name" : "Robbie Hatley" + "name" : "Robert DiCicco", + "id" : "Robert DiCicco" }, { "data" : [ @@ -116,28 +135,28 @@ 2 ] ], - "id" : "Roger Bell_West", - "name" : "Roger Bell_West" + "name" : "Roger Bell_West", + "id" : "Roger Bell_West" }, { + "name" : "Simon Proctor", "data" : [ [ "Raku", 2 ] ], - "id" : "Simon Proctor", - "name" : "Simon Proctor" + "id" : "Simon Proctor" }, { "id" : "Tim Potapov", + "name" : "Tim Potapov", "data" : [ [ "Perl", 2 ] - ], - "name" : "Tim Potapov" + ] }, { "id" : "W. Luis Mochan", @@ -155,21 +174,28 @@ } ] }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "subtitle" : { - "text" : "[Champions: 13] Last updated at 2022-11-22 14:24:39 GMT" + "legend" : { + "enabled" : 0 }, "tooltip" : { "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", - "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", - "followPointer" : 1 + "followPointer" : 1, + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>" }, - "chart" : { - "type" : "column" + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } + }, + "subtitle" : { + "text" : "[Champions: 14] Last updated at 2022-11-22 19:11:44 GMT" + }, + "title" : { + "text" : "The Weekly Challenge - 192" }, "series" : [ { @@ -182,23 +208,23 @@ "name" : "Dario Mazzeo" }, { - "name" : "E. Choroba", "drilldown" : "E. Choroba", - "y" : 2 + "y" : 2, + "name" : "E. Choroba" }, { + "y" : 2, "name" : "Humberto Massa", - "drilldown" : "Humberto Massa", - "y" : 2 + "drilldown" : "Humberto Massa" }, { - "name" : "James Smith", "y" : 3, + "name" : "James Smith", "drilldown" : "James Smith" }, { - "name" : "Mark Anderson", "drilldown" : "Mark Anderson", + "name" : "Mark Anderson", "y" : 2 }, { @@ -208,32 +234,37 @@ }, { "drilldown" : "Olivier Delouya", - "y" : 1, - "name" : "Olivier Delouya" + "name" : "Olivier Delouya", + "y" : 1 }, { - "name" : "Peter Campbell Smith", "drilldown" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith", "y" : 3 }, { "drilldown" : "Robbie Hatley", - "y" : 2, - "name" : "Robbie Hatley" + "name" : "Robbie Hatley", + "y" : 2 + }, + { + "name" : "Robert DiCicco", + "y" : 3, + "drilldown" : "Robert DiCicco" }, { - "name" : "Roger Bell_West", "drilldown" : "Roger Bell_West", + "name" : "Roger Bell_West", "y" : 4 }, { - "name" : "Simon Proctor", + "drilldown" : "Simon Proctor", "y" : 2, - "drilldown" : "Simon Proctor" + "name" : "Simon Proctor" }, { - "name" : "Tim Potapov", "y" : 2, + "name" : "Tim Potapov", "drilldown" : "Tim Potapov" }, { @@ -243,17 +274,5 @@ } ] } - ], - "xAxis" : { - "type" : "category" - }, - "plotOptions" : { - "series" : { - "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - }, - "borderWidth" : 0 - } - } + ] } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 293150e977..51915121aa 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,24 +1,10 @@ { - "legend" : { - "enabled" : "false" - }, - "title" : { - "text" : "The Weekly Challenge Contributions [2019 - 2022]" - }, - "xAxis" : { - "labels" : { - "style" : { - "fontSize" : "13px", - "fontFamily" : "Verdana, sans-serif" - } - }, - "type" : "category" - }, - "chart" : { - "type" : "column" + "subtitle" : { + "text" : "Last updated at 2022-11-22 19:11:44 GMT" }, "series" : [ { + "name" : "Contributions", "data" : [ [ "Blog", @@ -26,38 +12,52 @@ ], [ "Perl", - 9385 + 9387 ], [ "Raku", - 5632 + 5633 ] ], "dataLabels" : { - "color" : "#FFFFFF", - "enabled" : "true", "format" : "{point.y:.0f}", - "align" : "right", + "enabled" : "true", "rotation" : -90, - "y" : 10, "style" : { "fontFamily" : "Verdana, sans-serif", "fontSize" : "13px" - } - }, - "name" : "Contributions" + }, + "y" : 10, + "align" : "right", + "color" : "#FFFFFF" + } } ], + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2022]" + }, "tooltip" : { "pointFormat" : "<b>{point.y:.0f}</b>" }, + "legend" : { + "enabled" : "false" + }, "yAxis" : { "title" : { "text" : null }, "min" : 0 }, - "subtitle" : { - "text" : "Last updated at 2022-11-22 14:24:39 GMT" + "chart" : { + "type" : "column" + }, + "xAxis" : { + "labels" : { + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + } + }, + "type" : "category" } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 7951688c61..760a582050 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,999 +1,20 @@ { + "tooltip" : { + "headerFormat" : "<span style=\"font-size:11px\"></span>", + "followPointer" : "true", + "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>" + }, "plotOptions" : { "series" : { "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" + "format" : "{point.y}", + "enabled" : 1 }, "borderWidth" : 0 } }, - "xAxis" : { - "type" : "category" - }, - "series" : [ - { - "data" : [ - { - "y" : 161, - "drilldown" : "001", - "name" : "#001" - }, - { - "y" : 125, - "drilldown" : "002", - "name" : "#002" - }, - { - "drilldown" : "003", - "y" : 83, - "name" : "#003" - }, - { - "name" : "#004", - "y" : 99, - "drilldown" : "004" - }, - { - "drilldown" : "005", - "y" : 78, - "name" : "#005" - }, - { - "drilldown" : "006", - "y" : 58, - "name" : "#006" - }, - { - "name" : "#007", - "drilldown" : "007", - "y" : 65 - }, - { - "name" : "#008", - "y" : 78, - "drilldown" : "008" - }, - { - "name" : "#009", - "y" : 76, - "drilldown" : "009" - }, - { - "y" : 65, - "drilldown" : "010", - "name" : "#010" - }, - { - "name" : "#011", - "drilldown" : "011", - "y" : 85 - }, - { - |
