diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-05 10:52:30 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-05 10:52:30 +0100 |
| commit | 68838929af6ac82c8cc9cf61831edfcf90e86793 (patch) | |
| tree | a94258ee2c124a5a726c8d6a7fc958158e4d57c6 | |
| parent | ca4fe9d2ded0e61630a63a53da7525a720c3d87a (diff) | |
| download | perlweeklychallenge-club-68838929af6ac82c8cc9cf61831edfcf90e86793.tar.gz perlweeklychallenge-club-68838929af6ac82c8cc9cf61831edfcf90e86793.tar.bz2 perlweeklychallenge-club-68838929af6ac82c8cc9cf61831edfcf90e86793.zip | |
- Added solutions by Avery Adams.
- Added solutions by Bob Lied.
- Added solutions by Feng Chang.
- Added solutions by Laurent Rosenfeld.
- Added solutions by Leo Manfredi.
- Added solutions by Paulo Custodio.
- Added solutions by Robert Ransbottom.
- Added solutions by Roger Bell_West.
30 files changed, 3509 insertions, 3018 deletions
diff --git a/challenge-215/laurent-rosenfeld/blog.txt b/challenge-215/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..c21de67b01 --- /dev/null +++ b/challenge-215/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2023/05/perl-weekly-challenge-215-odd-one-out-and-number-placement.html diff --git a/challenge-215/laurent-rosenfeld/perl/ch-1.pl b/challenge-215/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..b1b8724b24 --- /dev/null +++ b/challenge-215/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,23 @@ +use strict; +use warnings; +use feature 'say'; + +sub find_non_sorted { + my @in = @_; + my @out = $in[0]; + my $count = 0; + for my $i (1..$#in) { + if ($in[$i] lt $in[$i-1]) { + $count++; + } else { + push @out, $in[$i]; + } + } + # say @out; + return $count; +} + +for my $test ([<abc xyz tsu>], [<rat cab dad>], [<x y z>]) { + printf "%-15s => ", "@$test"; + say find_non_sorted @$test; +} diff --git a/challenge-215/laurent-rosenfeld/perl/ch-2.pl b/challenge-215/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..5971e4b148 --- /dev/null +++ b/challenge-215/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,20 @@ +use strict; +use warnings; +use feature 'say'; + +sub find_zeros { + my @in = @{$_[0]}; + my $count = $_[1]; + return 0 if $count == 0 or @in < $count; + my $str = join "", @in; + return 1 if $str =~ /(?<!1)0{$count}(?!1)/; + 0; +} + +for my $test ([<0 0 0 1>], [<0 0>], [<1 0 0 1>], [<1 0 0 0 1>], + [<1 0 0 0 0 0 0 1>]) { + for my $cnt (0..5) { + printf "%d - %-16s => ", $cnt, "@$test"; + say find_zeros $test, $cnt; + } +} diff --git a/challenge-215/laurent-rosenfeld/raku/ch-1.raku b/challenge-215/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..4b32d50680 --- /dev/null +++ b/challenge-215/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,17 @@ +sub find-non-sorted (@in) { + my @out = @in[0]; + my $count = 0; + for 1..@in.end -> $i { + if @in[$i] lt @in[$i-1] { + $count++; + } else { + push @out, @in[$i]; + } + } + say @out; + return $count; +} +for <abc xyz tsu>, <rat cab dad>, <x y z> -> @test { + printf "%-15s => ", ~@test; + say find-non-sorted @test; +} diff --git a/challenge-215/laurent-rosenfeld/raku/ch-2.raku b/challenge-215/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..e50b23d8f2 --- /dev/null +++ b/challenge-215/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,13 @@ +sub find-zeros (@in, $count) { + return False if $count == 0 or @in.elems < $count; + my $str = join "", @in; + return so ($str ~~ / <!after 1> [0 ** {$count}] <!before 1>/) +} + +for <0 0 0 1>, <0 0>, <1 0 0 1>, <1 0 0 0 1>, + <1 0 0 0 0 0 0 1> -> @test { + for 0..5 -> $cnt { + printf "%d - %-16s => ", $cnt, "@test[]"; + say + find-zeros @test, $cnt; + } +} diff --git a/challenge-215/robert-dicicco/julia/ch-2.jl b/challenge-215/robert-dicicco/julia/ch-2.jl new file mode 100644 index 0000000000..792dcf078e --- /dev/null +++ b/challenge-215/robert-dicicco/julia/ch-2.jl @@ -0,0 +1,66 @@ +#!/usr/bin/env julia +#= +----------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-03 +Challenge 215 Number Placement ( Julia ) +----------------------------------------- +=# +using Printf + +numbers = [[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,0,0,0,0,1]]; +counts = [1,2,3] + +cnt=1 + +function CheckZeroes(arr) + zcnt = 1; + while zcnt < length(arr) + if ((arr[zcnt] == 0) && (arr[zcnt-1] == 0)) + arr[zcnt] = 1; + end + zcnt += 1; + end + @printf("Output: 1 = %s\n\n",arr) +end + +function HowManyZeroes(arr) + z = 1 + zcnt = 0 + while z < (length(arr)) + if (arr[z] == 0) + zcnt += 1 + end + z += 1 + end + return zcnt +end + +for nums in numbers + global cnt + @printf("Input: @numbers = %s Count = %d\n",nums,counts[cnt]) + zeroes = HowManyZeroes(nums) + if (zeroes < cnt * 2) + @printf("Output: 0\n\n") + else + CheckZeroes(nums) + end + cnt += 1 +end + +#= +----------------------------------------- +SAMPLE OUTPUT +julia .\NumberPlacement.jl +Input: @numbers = [1, 0, 0, 0, 1] Count = 1 +Output: 1 = [1, 0, 1, 0, 1] + +Input: @numbers = [1, 0, 0, 0, 1] Count = 2 +Output: 0 + +Input: @numbers = [1, 0, 0, 0, 0, 0, 0, 0, 1] Count = 3 +Output: 1 = [1, 0, 1, 0, 1, 0, 1, 0, 1] +----------------------------------------- +=# + + diff --git a/challenge-215/robert-dicicco/perl/ch-2.pl b/challenge-215/robert-dicicco/perl/ch-2.pl index 2a247a48c3..0a7056ec2d 100644 --- a/challenge-215/robert-dicicco/perl/ch-2.pl +++ b/challenge-215/robert-dicicco/perl/ch-2.pl @@ -5,6 +5,7 @@ AUTHOR: Robert DiCicco DATE : 2023-05-02 Challenge 215 Number Placement ( Perl ) ----------------------------------------- +* corrected version =cut use strict; use warnings; @@ -16,7 +17,7 @@ sub CheckZeroes { my $cnt = shift; my $zcnt = $cnt * 2; while($zcnt < scalar @$arr - 1) { - if ((@$arr[$zcnt] == 0) && (@$arr[$zcnt-1] != 1)) { + if ((@$arr[$zcnt] == 0) && (@$arr[$zcnt-1] == 0)) { @$arr[$zcnt] = 1; } $zcnt++; @@ -48,7 +49,7 @@ my $zeroes = HowManyZeroes(\@numbers); if ($zeroes < $count * 2) { say "Output: 0"; } else { - CheckZeroes(\@numbers,$count-1); + CheckZeroes(\@numbers,$count-3); } =begin pod @@ -65,7 +66,7 @@ Enter count 2 Output: 0 perl .\NumberPlacement.pl -Enter an array as a string of numbers 101000001 +Enter an array as a string of numbers 100000001 Enter count 3 Output: 1 = 101010101 ----------------------------------------- diff --git a/challenge-215/robert-dicicco/python/ch-2.py b/challenge-215/robert-dicicco/python/ch-2.py new file mode 100644 index 0000000000..647140cd24 --- /dev/null +++ b/challenge-215/robert-dicicco/python/ch-2.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# ----------------------------------------- +# AUTHOR: Robert DiCicco +# DATE : 2023-05-03 +# Challenge 215 Number Placement ( Python ) +# ----------------------------------------- + +numbers = [[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,0,0,0,0,1]]; +counts = [1,2,3] + +cnt=0 + +def CheckZeroes(arr): + zcnt = 1; + while zcnt < len(arr): + if ((arr[zcnt] == 0) and (arr[zcnt-1] == 0)): + arr[zcnt] = 1 + zcnt += 1; + print(f"Output: 1 = {arr}\n") + + +def HowManyZeroes(arr): + z = 0 + zcnt = 0 + while z < (len(arr)): + if (arr[z] == 0): + zcnt += 1 + z += 1 + return zcnt + + +for nums in numbers: + print(f"Input: @numbers = {nums} Count = {counts[cnt]}") + zeroes = HowManyZeroes(nums) + if (zeroes < (counts[cnt] * 2)): + print("Output: 0\n") + else: + CheckZeroes(nums) + cnt += 1 +# ----------------------------------------- +# SAMPLE OUTPUT +# python .\NumberPlacement.py +# Input: @numbers = [1, 0, 0, 0, 1] Count = 1 +# Output: 1 = [1, 0, 1, 0, 1] + +# Input: @numbers = [1, 0, 0, 0, 1] Count = 2 +# Output: 0 + +# Input: @numbers = [1, 0, 0, 0, 0, 0, 0, 0, 1] Count = 3 +# Output: 1 = [1, 0, 1, 0, 1, 0, 1, 0, 1] +# ----------------------------------------- + + diff --git a/challenge-215/robert-dicicco/raku/ch-2.raku b/challenge-215/robert-dicicco/raku/ch-2.raku index da1a5ce11c..ea5efcba16 100644 --- a/challenge-215/robert-dicicco/raku/ch-2.raku +++ b/challenge-215/robert-dicicco/raku/ch-2.raku @@ -3,7 +3,7 @@ ----------------------------------------- AUTHOR: Robert DiCicco DATE : 2023-05-02 -Challenge 215 Number Placement ( Raku ) +Challenge 215 Number Placement ( Raku ) CORRECTED VERSION When entering, the first digit is the count, the remainder is the array For example, the first example would be 1 1 0 0 0 1 @@ -12,10 +12,11 @@ which stands for a count of one, with array 1 0 0 0 1 } use v6; -sub CheckZeroes(@arr is copy, $cnt) { - my $zcnt = $cnt * 2; +sub CheckZeroes(@arr is copy) { + my $zcnt = 0; + #say "zcnt = $zcnt"; while $zcnt < @arr.elems - 1 { - if ((@arr[$zcnt] == 0) && (@arr[$zcnt-1] != 1)) { + if ((@arr[$zcnt] == 0) && (@arr[$zcnt-1] == 0)) { @arr[$zcnt] = 1; } $zcnt++; @@ -39,14 +40,14 @@ unit sub MAIN ($count where 0 <= $count <= 9, *@numbers where @numbers.elems > 0 say "Input: \@numbers = ", @numbers; say "Count = $count"; -my $test = HowManyZeroes(@numbers); +#my $test = HowManyZeroes(@numbers); my $zeroes = HowManyZeroes(@numbers); if ($zeroes < $count * 2) { say "Output: 0"; } else { - CheckZeroes(@numbers,$count-1); + CheckZeroes(@numbers); } @@ -64,7 +65,7 @@ Count = 2 Output: 0 PS G:\Projects\Perl\Challenges> raku .\NumberPlacement.rk 3 1 0 1 0 0 0 0 0 1 -Input: @numbers = [1 0 1 0 0 0 0 0 1] +Input: @numbers = [1 0 0 0 0 0 0 0 1] Count = 3 Output: 1 = [1 0 1 0 1 0 1 0 1] ----------------------------------------- diff --git a/challenge-215/robert-dicicco/ruby/ch-2.rb b/challenge-215/robert-dicicco/ruby/ch-2.rb new file mode 100644 index 0000000000..270c0ecd51 --- /dev/null +++ b/challenge-215/robert-dicicco/ruby/ch-2.rb @@ -0,0 +1,70 @@ +#!/usr/bin/env ruby +=begin +----------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-03 +Challenge 215 Number Placement ( Ruby ) +----------------------------------------- +=end + +numbers = [[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,0,0,0,0,1]]; +counts = [1,2,3] + +cnt = 0; + +def CheckZeroes(arr) + zcnt = 0; + while zcnt < arr.length() - 1 + if ((arr[zcnt] == 0) && (arr[zcnt-1] == 0)) + arr[zcnt] = 1; + end + zcnt += 1; + end + puts("Output: 1 = #{arr}") + puts("") +end + + +def HowManyZeroes(arr) + z = 0 + zcnt = 0 + while z < (arr.length()) - 1 + if (arr[z] == 0) + zcnt += 1 + end + z += 1 + end + return zcnt +end + +numbers.each do |nums| + puts("Input: @numbers = #{nums}") + puts("Count: #{counts[cnt]}") + cnt += 1 + zeroes = HowManyZeroes(nums) + if (zeroes < cnt * 2) + puts("Output: 0") + puts("") + else + CheckZeroes(nums) + end +end + +=begin +----------------------------------------- +ruby .\NumberPlacement.rb +Input: @numbers = [1, 0, 0, 0, 1] +Count: 1 +Output: 1 = [1, 0, 1, 0, 1] + +Input: @numbers = [1, 0, 0, 0, 1] +Count: 2 +Output: 0 + +Input: @numbers = [1, 0, 0, 0, 0, 0, 0, 0, 1] +Count: 3 +Output: 1 = [1, 0, 1, 0, 1, 0, 1, 0, 1] +----------------------------------------- +=end + + diff --git a/stats/pwc-challenge-210.json b/stats/pwc-challenge-210.json index bdc37b3b52..c2c8d94d43 100644 --- a/stats/pwc-challenge-210.json +++ b/stats/pwc-challenge-210.json @@ -1,196 +1,9 @@ { - "title" : { - "text" : "The Weekly Challenge - 210" - }, - "chart" : { - "type" : "column" - }, - "tooltip" : { - "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 - }, - "series" : [ - { - "data" : [ - { - "drilldown" : "Arne Sommer", - "y" : 3, - "name" : "Arne Sommer" - }, - { - "name" : "Athanasius", - "y" : 2, - "drilldown" : "Athanasius" - }, - { - "name" : "Avery Adams", - "y" : 3, - "drilldown" : "Avery Adams" - }, - { - "y" : 2, - "drilldown" : "Bob Lied", - "name" : "Bob Lied" - }, - { - "name" : "Carlos Oliveira", - "drilldown" : "Carlos Oliveira", - "y" : 2 - }, - { - "name" : "Cheok-Yin Fung", - "drilldown" : "Cheok-Yin Fung", - "y" : 1 - }, - { - "drilldown" : "Dave Jacoby", - "y" : 2, - "name" : "Dave Jacoby" - }, - { - "name" : "David Ferrone", - "drilldown" : "David Ferrone", - "y" : 2 - }, - { - "name" : "Duncan C. White", - "drilldown" : "Duncan C. White", - "y" : 2 - }, - { - "drilldown" : "E. Choroba", - "y" : 2, - "name" : "E. Choroba" - }, - { - "drilldown" : "Flavio Poletti", - "y" : 6, - "name" : "Flavio Poletti" - }, - { - "y" : 3, - "drilldown" : "James Smith", - "name" : "James Smith" - }, - { - "name" : "Jan Krnavek", - "y" : 1, - "drilldown" : "Jan Krnavek" - }, - { - "name" : "Jorg Sommrey", - "drilldown" : "Jorg Sommrey", - "y" : 2 - }, - { - "name" : "Laurent Rosenfeld", - "drilldown" : "Laurent Rosenfeld", - "y" : 4 - }, - { - "name" : "Luca Ferrari", - "y" : 8, - "drilldown" : "Luca Ferrari" - }, - { - "drilldown" : "Mariano Spadaccini", - "y" : 1, - "name" : "Mariano Spadaccini" - }, - { - "drilldown" : "Mark Anderson", - "y" : 2, - "name" : "Mark Anderson" - }, - { - "name" : "Matthew Neleigh", - "y" : 2, - "drilldown" : "Matthew Neleigh" - }, - { - "y" : 2, - "drilldown" : "Matthias Muth", - "name" : "Matthias Muth" - }, - { - "y" : 2, - "drilldown" : "Paulo Custodio", - "name" : "Paulo Custodio" - }, - { - "name" : "Peter Campbell Smith", - "y" : 3, - "drilldown" : "Peter Campbell Smith" - }, - { - "drilldown" : "Peter Meszaros", - "y" : 2, - "name" : "Peter Meszaros" - }, - { - "name" : "Pip Stuart", - "y" : 4, - "drilldown" : "Pip Stuart" - }, - { - "drilldown" : "Robbie Hatley", - "y" : 3, - "name" : "Robbie Hatley" - }, - { - "y" : 2, - "drilldown" : "Robert DiCicco", - "name" : "Robert DiCicco" - }, - { - "y" : 2, - "drilldown" : "Robert Ransbottom", - "name" : "Robert Ransbottom" - }, - { - "name" : "Roger Bell_West", - "y" : 5, - "drilldown" : "Roger Bell_West" - }, - { - "name" : "Shimon Bollinger", - "y" : 1, - "drilldown" : "Shimon Bollinger" - }, - { - "y" : 3, - "drilldown" : "Simon Green", - "name" : "Simon Green" - }, - { - "name" : "Solathian", - "drilldown" : "Solathian", - "y" : 2 - }, - { - "name" : "Thomas Kohler", - "drilldown" : "Thomas Kohler", - "y" : 4 - }, - { - "y" : 4, - "drilldown" : "Ulrich Rieke", - "name" : "Ulrich Rieke" - }, - { - "name" : "W. Luis Mochan", - "y" : 3, - "drilldown" : "W. Luis Mochan" - } - ], - "colorByPoint" : 1, - "name" : "The Weekly Challenge - 210" - } - ], "drilldown" : { "series" : [ { + "name" : "Arne Sommer", + "id" : "Arne Sommer", "data" : [ [ "Raku", @@ -200,11 +13,11 @@ "Blog", 1 ] - ], - "id" : "Arne Sommer", - "name" : "Arne Sommer" + ] }, { + "id" : "Athanasius", + "name" : "Athanasius", "data" : [ [ "Perl", @@ -214,13 +27,9 @@ "Raku", 1 ] - ], - "id" : "Athanasius", - "name" : "Athanasius" + ] }, { - "id" : "Avery Adams", - "name" : "Avery Adams", "data" : [ [ "Perl", @@ -230,7 +39,9 @@ "Blog", 1 ] - ] + ], + "id" : "Avery Adams", + "name" : "Avery Adams" }, { "id" : "Bob Lied", @@ -273,8 +84,18 @@ ] }, { - "name" : "David Ferrone", + "data" : [ + [ + "Perl", + 2 + ] + ], "id" : "David Ferrone", + "name" : "David Ferrone" + }, + { + "name" : "Duncan C. White", + "id" : "Duncan C. White", "data" : [ [ "Perl", @@ -283,26 +104,28 @@ ] }, { + "id" : "E. Choroba", + "name" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ], - "id" : "Duncan C. White", - "name" : "Duncan C. White" + ] }, { "data" : [ [ - "Perl", + "Raku", 2 ] ], - "name" : "E. Choroba", - "id" : "E. Choroba" + "name" : "Feng Chang", + "id" : "Feng Chang" }, { + "name" : "Flavio Poletti", + "id" : "Flavio Poletti", "data" : [ [ "Perl", @@ -316,11 +139,11 @@ "Blog", 2 ] - ], - "id" : "Flavio Poletti", - "name" : "Flavio Poletti" + ] }, { + "id" : "James Smith", + "name" : "James Smith", "data" : [ [ "Perl", @@ -330,9 +153,7 @@ "Blog", 1 ] - ], - "id" : "James Smith", - "name" : "James Smith" + ] }, { "name" : "Jan Krnavek", @@ -345,14 +166,14 @@ ] }, { + "name" : "Jorg Sommrey", + "id" : "Jorg Sommrey", "data" : [ [ "Perl", 2 ] - ], - "name" : "Jorg Sommrey", - "id" : "Jorg Sommrey" + ] }, { "name" : "Laurent Rosenfeld", @@ -373,8 +194,6 @@ ] }, { - "id" : "Luca Ferrari", - "name" : "Luca Ferrari", "data" : [ [ "Raku", @@ -384,17 +203,19 @@ "Blog", 6 ] - ] + ], + "id" : "Luca Ferrari", + "name" : "Luca Ferrari" }, { + "name" : "Mariano Spadaccini", + "id" : "Mariano Spadaccini", "data" : [ [ "Perl", 1 ] - ], - "name" : "Mariano Spadaccini", - "id" : "Mariano Spadaccini" + ] }, { "id" : "Mark Anderson", @@ -407,14 +228,14 @@ ] }, { - "name" : "Matthew Neleigh", - "id" : "Matthew Neleigh", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Matthew Neleigh", + "id" : "Matthew Neleigh" }, { "data" : [ @@ -427,16 +248,18 @@ "id" : "Matthias Muth" }, { + "id" : "Paulo Custodio", + "name" : "Paulo Custodio", "data" : [ [ "Perl", 2 ] - ], - "id" : "Paulo Custodio", - "name" : "Paulo Custodio" + ] }, { + "name" : "Peter Campbell Smith", + "id" : "Peter Campbell Smith", "data" : [ [ "Perl", @@ -446,23 +269,19 @@ "Blog", 1 ] - ], - "name" : "Peter Campbell Smith", - "id" : "Peter Campbell Smith" + ] }, { + "name" : "Peter Meszaros", + "id" : "Peter Meszaros", "data" : [ [ "Perl", 2 ] - ], - "id" : "Peter Meszaros", - "name" : "Peter Meszaros" + ] }, { - "name" : "Pip Stuart", - "id" : "Pip Stuart", "data" : [ [ "Perl", @@ -472,9 +291,13 @@ "Raku", 2 ] - ] + ], + "id" : "Pip Stuart", + "name" : "Pip Stuart" }, { + "name" : "Robbie Hatley", + "id" : "Robbie Hatley", "data" : [ [ "Perl", @@ -484,9 +307,7 @@ "Blog", 1 ] - ], - "id" : "Robbie Hatley", - "name" : "Robbie Hatley" + ] }, { "data" : [ @@ -513,8 +334,8 @@ "name" : "Robert Ransbottom" }, { - "name" : "Roger Bell_West", "id" : "Roger Bell_West", + "name" : "Roger Bell_West", "data" : [ [ "Perl", @@ -531,16 +352,18 @@ ] }, { + "id" : "Shimon Bollinger", + "name" : "Shimon Bollinger", "data" : [ [ "Raku", 1 ] - ], - "name" : "Shimon Bollinger", - "id" : "Shimon Bollinger" + ] }, { + "id" : "Simon Green", + "name" : "Simon Green", "data" : [ [ "Perl", @@ -550,21 +373,21 @@ "Blog", 1 |
