From 079976d9baaf0bfcc174a1465bc9f693f2630ae4 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 20 Sep 2023 15:45:30 +0100 Subject: - Added solutions by Roger Bell_West. - Added solutions by Mark Anderson. - Added solutions by Lubos Kolouch. - Added solutions by Niels van Dijke. - Added solutions by Humberto Massa. - Added solutions by Conor Hoekstra. - Added solutions by Laurent Rosenfeld. - Added solutions by Luca Ferrari. - Added solutions by David Ferrone. - Added solutions by W. Luis Mochan. - Added solutions by Thomas Kohler. - Added solutions by Dave Jacoby. - Added solutions by Packy Anderson. - Added solutions by Athanasius. - Added solutions by PokGoPun. - Added solutions by E. Choroba. - Added solutions by Steven Wilson. - Added solutions by Peter Meszaros. - Added solutions by Matthew Neleigh. - Added solutions by Ali Moradi. - Added solutions by Bob Lied. --- challenge-234/perlboy1967/perl/ch-1.pl | 52 + challenge-234/perlboy1967/perl/ch-2.pl | 48 + challenge-234/perlboy1967/perl/ch1.pl | 52 - challenge-234/perlboy1967/perl/ch2.pl | 48 - challenge-235/conor-hoekstra/bqn/ch-1.bqn | 7 + challenge-235/conor-hoekstra/bqn/ch-2.bqn | 6 + challenge-235/conor-hoekstra/ch-01.bqn | 7 - challenge-235/conor-hoekstra/ch-02.bqn | 6 - challenge-235/eric-cheung/python/ch-1.py | 23 + challenge-235/eric-cheung/python/ch-2.py | 14 + challenge-235/laurent-rosenfeld/blog.txt | 1 + challenge-235/laurent-rosenfeld/blog1.txt | 1 + challenge-235/laurent-rosenfeld/perl/ch-1.pl | 17 + challenge-235/laurent-rosenfeld/perl/ch-2.pl | 14 + challenge-235/laurent-rosenfeld/raku/ch-1.raku | 12 + challenge-235/laurent-rosenfeld/raku/ch-2.raku | 9 + challenge-235/perlboy1967/perl/ch-1.pl | 36 + challenge-235/perlboy1967/perl/ch-2.pl | 48 + challenge-235/perlboy1967/perl/ch1.pl | 36 - challenge-235/perlboy1967/perl/ch2.pl | 48 - challenge-235/robert-dicicco/julia/ch-1.jl | 61 + challenge-235/robert-dicicco/julia/ch-2.jl | 43 + challenge-235/robert-dicicco/perl/ch-1.pl | 57 + challenge-235/robert-dicicco/perl/ch-2.pl | 44 + challenge-235/robert-dicicco/powershell/ch-1.psl | 64 + challenge-235/robert-dicicco/powershell/ch-2.psl | 45 + challenge-235/robert-dicicco/python/ch-1.py | 59 + challenge-235/robert-dicicco/python/ch-2.py | 39 + challenge-235/robert-dicicco/raku/ch-1.raku | 58 + challenge-235/robert-dicicco/raku/ch-2.raku | 44 + challenge-235/robert-dicicco/ruby/ch-1.rb | 58 + challenge-235/robert-dicicco/ruby/ch-2.rb | 44 + challenge-235/robert-dicicco/tcl/ch-1.tcl | 64 + challenge-235/robert-dicicco/tcl/ch-2.tcl | 46 + challenge-235/steven-wilson/python/ch-01.py | 25 - challenge-235/steven-wilson/python/ch-02.py | 32 - challenge-235/steven-wilson/python/ch-1.py | 25 + challenge-235/steven-wilson/python/ch-2.py | 32 + challenge-235/ulrich-rieke/cpp/ch-1.cpp | 39 + challenge-235/ulrich-rieke/cpp/ch-2.cpp | 41 + challenge-235/ulrich-rieke/haskell/ch-1.hs | 17 + challenge-235/ulrich-rieke/haskell/ch-2.hs | 12 + challenge-235/ulrich-rieke/perl/ch-1.pl | 25 + challenge-235/ulrich-rieke/perl/ch-2.pl | 22 + challenge-235/ulrich-rieke/raku/ch-1.raku | 22 + challenge-235/ulrich-rieke/raku/ch-2.raku | 18 + challenge-235/ulrich-rieke/rust/ch-1.rs | 25 + challenge-235/ulrich-rieke/rust/ch-2.rs | 25 + stats/pwc-challenge-234.json | 669 +++++ stats/pwc-current.json | 606 ++-- stats/pwc-language-breakdown-summary.json | 68 +- stats/pwc-language-breakdown.json | 3247 +++++++++++----------- stats/pwc-leaders.json | 494 ++-- stats/pwc-summary-1-30.json | 50 +- stats/pwc-summary-121-150.json | 34 +- stats/pwc-summary-151-180.json | 128 +- stats/pwc-summary-181-210.json | 42 +- stats/pwc-summary-211-240.json | 104 +- stats/pwc-summary-241-270.json | 34 +- stats/pwc-summary-271-300.json | 68 +- stats/pwc-summary-31-60.json | 38 +- stats/pwc-summary-61-90.json | 44 +- stats/pwc-summary-91-120.json | 26 +- stats/pwc-summary.json | 1840 ++++++------ 64 files changed, 5286 insertions(+), 3777 deletions(-) create mode 100755 challenge-234/perlboy1967/perl/ch-1.pl create mode 100755 challenge-234/perlboy1967/perl/ch-2.pl delete mode 100755 challenge-234/perlboy1967/perl/ch1.pl delete mode 100755 challenge-234/perlboy1967/perl/ch2.pl create mode 100644 challenge-235/conor-hoekstra/bqn/ch-1.bqn create mode 100644 challenge-235/conor-hoekstra/bqn/ch-2.bqn delete mode 100644 challenge-235/conor-hoekstra/ch-01.bqn delete mode 100644 challenge-235/conor-hoekstra/ch-02.bqn create mode 100755 challenge-235/eric-cheung/python/ch-1.py create mode 100755 challenge-235/eric-cheung/python/ch-2.py create mode 100644 challenge-235/laurent-rosenfeld/blog.txt create mode 100644 challenge-235/laurent-rosenfeld/blog1.txt create mode 100644 challenge-235/laurent-rosenfeld/perl/ch-1.pl create mode 100644 challenge-235/laurent-rosenfeld/perl/ch-2.pl create mode 100644 challenge-235/laurent-rosenfeld/raku/ch-1.raku create mode 100644 challenge-235/laurent-rosenfeld/raku/ch-2.raku create mode 100755 challenge-235/perlboy1967/perl/ch-1.pl create mode 100755 challenge-235/perlboy1967/perl/ch-2.pl delete mode 100755 challenge-235/perlboy1967/perl/ch1.pl delete mode 100755 challenge-235/perlboy1967/perl/ch2.pl create mode 100644 challenge-235/robert-dicicco/julia/ch-1.jl create mode 100644 challenge-235/robert-dicicco/julia/ch-2.jl create mode 100644 challenge-235/robert-dicicco/perl/ch-1.pl create mode 100644 challenge-235/robert-dicicco/perl/ch-2.pl create mode 100644 challenge-235/robert-dicicco/powershell/ch-1.psl create mode 100644 challenge-235/robert-dicicco/powershell/ch-2.psl create mode 100644 challenge-235/robert-dicicco/python/ch-1.py create mode 100644 challenge-235/robert-dicicco/python/ch-2.py create mode 100644 challenge-235/robert-dicicco/raku/ch-1.raku create mode 100644 challenge-235/robert-dicicco/raku/ch-2.raku create mode 100644 challenge-235/robert-dicicco/ruby/ch-1.rb create mode 100644 challenge-235/robert-dicicco/ruby/ch-2.rb create mode 100644 challenge-235/robert-dicicco/tcl/ch-1.tcl create mode 100644 challenge-235/robert-dicicco/tcl/ch-2.tcl delete mode 100644 challenge-235/steven-wilson/python/ch-01.py delete mode 100644 challenge-235/steven-wilson/python/ch-02.py create mode 100644 challenge-235/steven-wilson/python/ch-1.py create mode 100644 challenge-235/steven-wilson/python/ch-2.py create mode 100755 challenge-235/ulrich-rieke/cpp/ch-1.cpp create mode 100755 challenge-235/ulrich-rieke/cpp/ch-2.cpp create mode 100755 challenge-235/ulrich-rieke/haskell/ch-1.hs create mode 100755 challenge-235/ulrich-rieke/haskell/ch-2.hs create mode 100755 challenge-235/ulrich-rieke/perl/ch-1.pl create mode 100755 challenge-235/ulrich-rieke/perl/ch-2.pl create mode 100755 challenge-235/ulrich-rieke/raku/ch-1.raku create mode 100755 challenge-235/ulrich-rieke/raku/ch-2.raku create mode 100755 challenge-235/ulrich-rieke/rust/ch-1.rs create mode 100755 challenge-235/ulrich-rieke/rust/ch-2.rs create mode 100644 stats/pwc-challenge-234.json diff --git a/challenge-234/perlboy1967/perl/ch-1.pl b/challenge-234/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..d0af0306ce --- /dev/null +++ b/challenge-234/perlboy1967/perl/ch-1.pl @@ -0,0 +1,52 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 234 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-234 + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Common Characters +Submitted by: Mohammad S Anwar + +You are given an array of words made up of alphabetic characters only. + +Write a script to return all alphabetic characters that show up in all +words including duplicates. + +=cut + +use v5.16; + +use common::sense; + +use Test::More; +use Test::Deep qw(cmp_deeply); + +use List::Util qw(min); + +sub commonCharacters (@) { + my (%c,%wc,@r); + + # Find (total and word) character frequencies + for (@_) { + for my $c (split //) { + $c{$c}++; + $wc{$c}{$_}++; + } + } + + # Find same frequency of characters across all words + for my $c (grep { $c{$_} >= scalar @_ } sort keys %c) { + push(@r,($c) x min map { $wc{$c}{$_} // 0 } @_); + } + + return @r; +} + +cmp_deeply([commonCharacters(qw{java javascript julia})],[qw{a j}]); +cmp_deeply([commonCharacters(qw{bella label roller})],[qw{e l l}]); +cmp_deeply([commonCharacters(qw{cool lock cook})],[qw{c o}]); + +done_testing; diff --git a/challenge-234/perlboy1967/perl/ch-2.pl b/challenge-234/perlboy1967/perl/ch-2.pl new file mode 100755 index 0000000000..6c937c1726 --- /dev/null +++ b/challenge-234/perlboy1967/perl/ch-2.pl @@ -0,0 +1,48 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 234 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-234 + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Unequal Triplets +Submitted by: Mohammad S Anwar + +You are given an array of positive integers. + +Write a script to find the number of triplets (i, j, k) that satisfies +num[i] != num[j], num[j] != num[k] and num[k] != num[i]. + +=cut + +use v5.16; + +use common::sense; + +use Test::More; + +use List::Util qw(sum0); +use Algorithm::Combinatorics qw(combinations); + +sub unequalTriplets (@) { + my (%f,@n,@r); + + $f{$_}++ for (@_); + @n = sort { $a <=> $b } keys %f; + + return 0 if (@n < 3); + + my @c = combinations(\@n,3); + push(@r, $f{$$_[0]} * $f{$$_[1]} * $f{$$_[2]}) for (@c); + + return sum0(@r); + +} + +is(unequalTriplets(4, 4, 2, 4, 3),3); +is(unequalTriplets(1, 1, 1, 1, 1),0); +is(unequalTriplets(4, 7, 1, 10, 7, 4, 1, 1), 28); + +done_testing; diff --git a/challenge-234/perlboy1967/perl/ch1.pl b/challenge-234/perlboy1967/perl/ch1.pl deleted file mode 100755 index d0af0306ce..0000000000 --- a/challenge-234/perlboy1967/perl/ch1.pl +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/perl - -=pod - -The Weekly Challenge - 234 -- https://theweeklychallenge.org/blog/perl-weekly-challenge-234 - -Author: Niels 'PerlBoy' van Dijke - -Task 1: Common Characters -Submitted by: Mohammad S Anwar - -You are given an array of words made up of alphabetic characters only. - -Write a script to return all alphabetic characters that show up in all -words including duplicates. - -=cut - -use v5.16; - -use common::sense; - -use Test::More; -use Test::Deep qw(cmp_deeply); - -use List::Util qw(min); - -sub commonCharacters (@) { - my (%c,%wc,@r); - - # Find (total and word) character frequencies - for (@_) { - for my $c (split //) { - $c{$c}++; - $wc{$c}{$_}++; - } - } - - # Find same frequency of characters across all words - for my $c (grep { $c{$_} >= scalar @_ } sort keys %c) { - push(@r,($c) x min map { $wc{$c}{$_} // 0 } @_); - } - - return @r; -} - -cmp_deeply([commonCharacters(qw{java javascript julia})],[qw{a j}]); -cmp_deeply([commonCharacters(qw{bella label roller})],[qw{e l l}]); -cmp_deeply([commonCharacters(qw{cool lock cook})],[qw{c o}]); - -done_testing; diff --git a/challenge-234/perlboy1967/perl/ch2.pl b/challenge-234/perlboy1967/perl/ch2.pl deleted file mode 100755 index 6c937c1726..0000000000 --- a/challenge-234/perlboy1967/perl/ch2.pl +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/perl - -=pod - -The Weekly Challenge - 234 -- https://theweeklychallenge.org/blog/perl-weekly-challenge-234 - -Author: Niels 'PerlBoy' van Dijke - -Task 2: Unequal Triplets -Submitted by: Mohammad S Anwar - -You are given an array of positive integers. - -Write a script to find the number of triplets (i, j, k) that satisfies -num[i] != num[j], num[j] != num[k] and num[k] != num[i]. - -=cut - -use v5.16; - -use common::sense; - -use Test::More; - -use List::Util qw(sum0); -use Algorithm::Combinatorics qw(combinations); - -sub unequalTriplets (@) { - my (%f,@n,@r); - - $f{$_}++ for (@_); - @n = sort { $a <=> $b } keys %f; - - return 0 if (@n < 3); - - my @c = combinations(\@n,3); - push(@r, $f{$$_[0]} * $f{$$_[1]} * $f{$$_[2]}) for (@c); - - return sum0(@r); - -} - -is(unequalTriplets(4, 4, 2, 4, 3),3); -is(unequalTriplets(1, 1, 1, 1, 1),0); -is(unequalTriplets(4, 7, 1, 10, 7, 4, 1, 1), 28); - -done_testing; diff --git a/challenge-235/conor-hoekstra/bqn/ch-1.bqn b/challenge-235/conor-hoekstra/bqn/ch-1.bqn new file mode 100644 index 0000000000..947466daf6 --- /dev/null +++ b/challenge-235/conor-hoekstra/bqn/ch-1.bqn @@ -0,0 +1,7 @@ +DupZeroes ← {(≠𝕩)↑𝕩/˜1+0=𝕩} # Explicit +DupZeroes ← ≠↑(1+0=⊢)⊸/ # Tacit + +# Tests +DupZeroes ⟨1,0,2,3,0,4,5,0⟩ # ⟨ 1 0 0 2 3 0 0 4 ⟩ +DupZeroes ⟨1,2,3⟩ # ⟨ 1 2 3 ⟩ +DupZeroes ⟨0,3,0,4,5⟩ # ⟨ 0 0 3 0 0 ⟩ diff --git a/challenge-235/conor-hoekstra/bqn/ch-2.bqn b/challenge-235/conor-hoekstra/bqn/ch-2.bqn new file mode 100644 index 0000000000..3058709816 --- /dev/null +++ b/challenge-235/conor-hoekstra/bqn/ch-2.bqn @@ -0,0 +1,6 @@ +RemoveOne ← {1≥+´0≤-´˘2↕𝕩} + +# Tests +RemoveOne ⟨0,2,9,4,6⟩ # 1 +RemoveOne ⟨5,1,3,2⟩ # 0 +RemoveOne ⟨2,2,3⟩ # 1 diff --git a/challenge-235/conor-hoekstra/ch-01.bqn b/challenge-235/conor-hoekstra/ch-01.bqn deleted file mode 100644 index 947466daf6..0000000000 --- a/challenge-235/conor-hoekstra/ch-01.bqn +++ /dev/null @@ -1,7 +0,0 @@ -DupZeroes ← {(≠𝕩)↑𝕩/˜1+0=𝕩} # Explicit -DupZeroes ← ≠↑(1+0=⊢)⊸/ # Tacit - -# Tests -DupZeroes ⟨1,0,2,3,0,4,5,0⟩ # ⟨ 1 0 0 2 3 0 0 4 ⟩ -DupZeroes ⟨1,2,3⟩ # ⟨ 1 2 3 ⟩ -DupZeroes ⟨0,3,0,4,5⟩ # ⟨ 0 0 3 0 0 ⟩ diff --git a/challenge-235/conor-hoekstra/ch-02.bqn b/challenge-235/conor-hoekstra/ch-02.bqn deleted file mode 100644 index 3058709816..0000000000 --- a/challenge-235/conor-hoekstra/ch-02.bqn +++ /dev/null @@ -1,6 +0,0 @@ -RemoveOne ← {1≥+´0≤-´˘2↕𝕩} - -# Tests -RemoveOne ⟨0,2,9,4,6⟩ # 1 -RemoveOne ⟨5,1,3,2⟩ # 0 -RemoveOne ⟨2,2,3⟩ # 1 diff --git a/challenge-235/eric-cheung/python/ch-1.py b/challenge-235/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..4db77ca820 --- /dev/null +++ b/challenge-235/eric-cheung/python/ch-1.py @@ -0,0 +1,23 @@ + +def IsStrictInc (arrCheck): + + for nIndx in range(1, len(arrCheck)): + if arrCheck[nIndx] <= arrCheck[nIndx - 1]: + return False + + return True + +## arrInput = [0, 2, 9, 4, 6] ## Example 1 +## arrInput = [5, 1, 3, 2] ## Example 2 +arrInput = [2, 2, 3] ## Example 3 + +bIsRemoveOne = False + +for nLoop in range(len(arrInput)): + arrTemp = arrInput[:] + arrTemp.pop(nLoop) + if IsStrictInc (arrTemp): + bIsRemoveOne = True + break + +print (bIsRemoveOne) diff --git a/challenge-235/eric-cheung/python/ch-2.py b/challenge-235/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..ac11360c2d --- /dev/null +++ b/challenge-235/eric-cheung/python/ch-2.py @@ -0,0 +1,14 @@ + +## arrInput = [1, 0, 2, 3, 0, 4, 5, 0] ## Example 1 +## arrInput = [1, 2, 3] ## Example 2 +arrInput = [0, 3, 0, 4, 5] ## Example 3 + +arrTemp = arrInput[:] + +for nIndx in range(len(arrInput) - 1, -1, -1): + if arrTemp[nIndx] == 0: + arrTemp.insert(nIndx, 0) + +arrOutput = arrTemp[:len(arrInput)] + +print (arrOutput) diff --git a/challenge-235/laurent-rosenfeld/blog.txt b/challenge-235/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..7f5e034175 --- /dev/null +++ b/challenge-235/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2023/09/perl-weekly-challenge-235-remove-one.html diff --git a/challenge-235/laurent-rosenfeld/blog1.txt b/challenge-235/laurent-rosenfeld/blog1.txt new file mode 100644 index 0000000000..c06c47fc94 --- /dev/null +++ b/challenge-235/laurent-rosenfeld/blog1.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2023/09/perl-weekly-challenge-235-duplicate-zeros.html diff --git a/challenge-235/laurent-rosenfeld/perl/ch-1.pl b/challenge-235/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..48b034c7bc --- /dev/null +++ b/challenge-235/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,17 @@ +use strict; +use warnings; +use feature 'say'; + +sub can_strictly_increase { + my $count = 0; + for my $i (1..$#_) { + $count++ if $_[$i-1] >= $_[$i]; + } + return $count > 1 ? "false" : "true"; +} + +for my $test ([<0 2 9 4 6>], [<5 1 3 2>], + [<2 2 3>], [<3 3 3>]) { + printf "%-12s => ", "@$test"; + say can_strictly_increase @$test; +} diff --git a/challenge-235/laurent-rosenfeld/perl/ch-2.pl b/challenge-235/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..949fd414b8 --- /dev/null +++ b/challenge-235/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,14 @@ +use strict; +use warnings; +use feature 'say'; + +sub duplicate_zeros { + my @result = map { $_ == 0 ? (0, 0) : $_ } @_; + return @result[0..$#_]; +} + +for my $test ([<1 0 2 3 0 4 5 0>], + [<1 2 3>], [<0 3 0 4 5>]) { + printf "%-18s => ", "@$test"; + say join " ", duplicate_zeros @$test; +} diff --git a/challenge-235/laurent-rosenfeld/raku/ch-1.raku b/challenge-235/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..edd37c4b44 --- /dev/null +++ b/challenge-235/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,12 @@ +sub can-strictly-increase (@in) { + my $count = 0; + for 1..@in.end -> $i { + $count++ if @in[$i-1] >= @in[$i]; + } + return $count > 1 ?? False !! True; +} + +for <0 2 9 4 6>, <5 1 3 2>, <2 2 3>, <3 3 3> -> @test { + printf "%-12s => ", "@test[]"; + say can-strictly-increase @test; +} diff --git a/challenge-235/laurent-rosenfeld/raku/ch-2.raku b/challenge-235/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..87d2ed3401 --- /dev/null +++ b/challenge-235/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,9 @@ +sub duplicate-zeros (@in) { + my @result = map { $_ == 0 ?? |(0, 0) !! $_ }, @in; + return @result[0..@in.end]; +} + +for <1 0 2 3 0 4 5 0>, <1 2 3>, <0 3 0 4 5> -> @test { + printf "%-18s => ", "@test[]"; + say duplicate-zeros @test; +} diff --git a/challenge-235/perlboy1967/perl/ch-1.pl b/challenge-235/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..568f809937 --- /dev/null +++ b/challenge-235/perlboy1967/perl/ch-1.pl @@ -0,0 +1,36 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 235 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-235 + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Remove One +Submitted by: Mohammad S Anwar + +You are given an array of integers. + +Write a script to find out if removing ONLY one integer makes it strictly increasing order. + +=cut + +use v5.16; + +use common::sense; + +use Test::More; + +use List::MoreUtils qw(slide); + +sub removeOne (@) { + scalar(grep { $_ < 0 } slide { $b - $a } @_) <= 1 ? 1 : 0; +} + +is(removeOne(0, 2, 9, 4, 6), 1); +is(removeOne(5, 1, 3, 2), 0); +is(removeOne(2, 2, 3), 1); + +done_testing; + diff --git a/challenge-235/perlboy1967/perl/ch-2.pl b/challenge-235/perlboy1967/perl/ch-2.pl new file mode 100755 index 0000000000..bd9b273777 --- /dev/null +++ b/challenge-235/perlboy1967/perl/ch-2.pl @@ -0,0 +1,48 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 235 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-235 + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Duplicate Zeros +Submitted by: Mohammad S Anwar + +You are given an array of integers. + +Write a script to duplicate each occurrence of ZERO in the given array and +shift the remaining to the right but make sure the size of array remain the same. + +=cut + +use v5.16; + +use common::sense; + +use Test::More; +use Test::Deep qw(cmp_deeply); + +sub duplicateZeros (@) { + my @r; + + for (@_) { + push(@r,$_); + if ($r[-1] == 0) { + push(@r,0); pop(@_) + } + } + + return @r; +} + +cmp_deeply([duplicateZeros(1, 0, 2, 3, 0, 4, 5, 0)], + [1, 0, 0, 2, 3, 0, 0, 4]); +cmp_deeply([duplicateZeros(1, 2 , 3)], + [1, 2, 3]); +cmp_deeply([duplicateZeros(0, 3, 0, 4, 5)], + [0, 0, 3, 0, 0]); + +done_testing; + diff --git a/challenge-235/perlboy1967/perl/ch1.pl b/challenge-235/perlboy1967/perl/ch1.pl deleted file mode 100755 index 568f809937..0000000000 --- a/challenge-235/perlboy1967/perl/ch1.pl +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/perl - -=pod - -The Weekly Challenge - 235 -- https://theweeklychallenge.org/blog/perl-weekly-challenge-235 - -Author: Niels 'PerlBoy' van Dijke - -Task 1: Remove One -Submitted by: Mohammad S Anwar - -You are given an array of integers. - -Write a script to find out if removing ONLY one integer makes it strictly increasing order. - -=cut - -use v5.16; - -use common::sense; - -use Test::More; - -use List::MoreUtils qw(slide); - -sub removeOne (@) { - scalar(grep { $_ < 0 } slide { $b - $a } @_) <= 1 ? 1 : 0; -} - -is(removeOne(0, 2, 9, 4, 6), 1); -is(removeOne(5, 1, 3, 2), 0); -is(removeOne(2, 2, 3), 1); - -done_testing; - diff --git a/challenge-235/perlboy1967/perl/ch2.pl b/challenge-235/perlboy1967/perl/ch2.pl deleted file mode 100755 index bd9b273777..0000000000 --- a/challenge-235/perlboy1967/perl/ch2.pl +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/perl - -=pod - -The Weekly Challenge - 235 -- https://theweeklychallenge.org/blog/perl-weekly-challenge-235 - -Author: Niels 'PerlBoy' van Dijke - -Task 2: Duplicate Zeros -Submitted by: Mohammad S Anwar - -You are given an array of integers. - -Write a script to duplicate each occurrence of ZERO in the given array and -shift the remaining to the right but make sure the size of array remain the same. - -=cut - -use v5.16; - -use common::sense; - -use Test::More; -use Test::Deep qw(cmp_deeply); - -sub duplicateZeros (@) { - my @r; - - for (@_) { - push(@r,$_); - if ($r[-1] == 0) { - push(@r,0); pop(@_) - } - } - - return @r; -} - -cmp_deeply([duplicateZeros(1, 0, 2, 3, 0, 4, 5, 0)], - [1, 0, 0, 2, 3, 0, 0, 4]); -cmp_deeply([duplicateZeros(1, 2 , 3)], - [1, 2, 3]); -cmp_deeply([duplicateZeros(0, 3, 0, 4, 5)], - [0, 0, 3, 0, 0]); - -done_testing; - diff --git a/challenge-235/robert-dicicco/julia/ch-1.jl b/challenge-235/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..723294e65b --- /dev/null +++ b/challenge-235/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,61 @@ +#!/usr/bin/env julia +#= +--------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-09-18 +Challenge 235 Task 1 Remove One ( Julia ) +--------------------------------------- +=# + +using Printf + +myints = [[0, 2, 9, 4, 6],[5, 1, 3, 2],[2, 2, 3]] + +for mints in myints + @printf("Input: @ints = %s\n",mints) + len = length(mints) + cnt = 0 + x = 2 + while x <= len + if mints[x] > mints[x-1] + @printf("\t%d greater than %d\n", mints[x], mints[x-1]) + x += 1 + elseif mints[x] == mints[x-1] + @printf("\t%d equal to %d\n", mints[x], mints[x-1]) + x += 1 + cnt += 1 + else + @printf("\t%d less than %d\n", mints[x], mints[x-1]) + x += 1 + cnt += 1 + end + end + cnt == 1 ? println("Output: true\n") : println("Output: false\n") +end + +#= +--------------------------------------- +SAMPLE OUTPUT +julia .\RemoveOne.jl + +Input: @ints = [0, 2, 9, 4, 6] + 2 greater than 0 + 9 greater than 2 + 4 less than 9 + 6 greater than 4 +Output: true + +Input: @ints = [5, 1, 3, 2] + 1 less than 5 + 3 greater than 1 + 2 less than 3 +Output: false + +Input: @ints = [2, 2, 3] + 2 equal to 2 + 3 greater than 2 +Output: true +--------------------------------------- +=# + + diff --git a/challenge-235/robert-dicicco/julia/ch-2.jl b/challenge-235/robert-dicicco/julia/ch-2.jl new file mode 100644 index 0000000000..b09bac7671 --- /dev/null +++ b/challenge-235/robert-dicicco/julia/ch-2.jl @@ -0,0 +1,43 @@ +#!/usr/bin/env julia +#= +------------------------------------------ +AUTHOR: Robert DiCicco +DATE ; 2023-09-18 +Challenge 235 Task 02 Duplicate Zaroes ( Julia ) +------------------------------------------ +=# +using Printf + +myints = [[1, 0, 2, 3, 0, 4, 5, 0],[1, 2, 3],[0, 3, 0, 4, 5]] + +for mints in myints + @printf("Input: @ints = %s\n", mints) + seen = [] + len = length(mints) + for x in mints + if x == 0 + push!(seen, 0,0) + else + push!(seen, x) + end + end + @printf("Output: %s\n\n",seen[1:len]) +end + +#= +------------------------------------------ +SAMPLE OUTPUT +julia .\DuplicateZeros.jl + +Input: @ints = [1, 0, 2, 3, 0, 4, 5, 0] +Output: Any[1, 0, 0, 2, 3, 0, 0, 4] + +Input: @ints = [1, 2, 3] +Output: Any[1, 2, 3] + +Input: @ints = [0, 3, 0, 4, 5] +Output: Any[0, 0, 3, 0, 0] +------------------------------------------ +=# + + diff --git a/challenge-235/robert-dicicco/perl/ch-1.pl b/challenge-235/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..5a807a4ac5 --- /dev/null +++ b/challenge-235/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,57 @@ +#!/usr/bin/env perl +=begin comment +--------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-09-18 +Challenge 235 Task 1 Remove One ( Perl ) +--------------------------------------- +=cut + +use v5.38; + +my @myints = ([0, 2, 9, 4, 6],[5, 1, 3, 2],[2, 2, 3]); + +for my $mints (@myints) { + say "Input: \@ints = [@$mints]"; + my $len = scalar @$mints; + my $cnt = 0; + my $x = 1; + while($x < $len) { + if (@$mints[$x] > @$mints[$x - 1]) { + say "\t@$mints[$x] greater than @$mints[$x - 1]"; + $x++; + } else { + say "\t@$mints[$x] less than @$mints[$x - 1]"; + $cnt++; + $x++; + } + } + $cnt == 1 ? say "Output: true\n" : say "Output: false\n"; +} + +=begin comment +--------------------------------------- +SAMPLE OUTPUT +perl .\RemoveOne.pl + +Input: @ints = [0 2 9 4 6] + 2 greater than 0 + 9 greater than 2 + 4 less than 9 + 6 greater than 4 +Output: true + +Input: @ints = [5 1 3 2] + 1 less than 5 + 3 greater than 1 + 2 less than 3 +Output: false + +Input: @ints = [2 2 3] + 2 less than 2 + 3 greater than 2 +Output: true +--------------------------------------- +=cut + + diff --git a/challenge-235/robert-dicicco/perl/ch-2.pl b/challenge-235/robert-dicicco/perl/ch-2.pl new file mode 100644 index 0000000000..d96833b764 --- /dev/null +++ b/challenge-235/robert-dicicco/perl/ch-2.pl @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +=begin comment +------------------------------------------ +AUTHOR: Robert DiCicco +DATE ; 2023-09-18 +Challenge Task 02 Duplicate Zaroes ( Perl ) +------------------------------------------ +=cut + +use v5.38; +my @myints = ([1, 0, 2, 3, 0, 4, 5, 0],[1, 2, 3],[0, 3, 0, 4, 5]); + +for my $mints (@myints) { + say "Input: \@ints = [@$mints]"; + my @seen = (); + my $len = scalar @$mints - 1; + for my $x (@$mints) { + if ($x != 0) { + push(@seen, $x); + } else { + push(@seen, 0); + push(@seen, 0); + } + } + say "Output: [@seen[0..$len]]\n"; +} + +=begin comment +------------------------------------------ +SAMPLE OUTPUT +perl .\DuplicateZeros.pl + +Input: @ints = [1 0 2 3 0 4 5 0] +Output: [1 0 0 2 3 0 0 4] + +Input: @ints = [1 2 3] +Output: [1 2 3] + +Input: @ints = [0 3 0 4 5] +Output: [0 0 3 0 0] +------------------------------------------ +=cut + + diff --git a/challenge-235/robert-dicicco/powershell/ch-1.psl b/challenge-235/robert-dicicco/powershell/ch-1.psl new file mode 100644 index 0000000000..1362a6c41b --- /dev/null +++ b/challenge-235/robert-dicicco/powershell/ch-1.psl @@ -0,0 +1,64 @@ +<# +------------------------------------------ +AUTHOR: Robert DiCicco +DATE ; 2023-09-20 +Challenge 235 Task 01 Remove One ( Powershell ) +------------------------------------------ +#> +$myints = @( (0, 2, 9, 4, 6), (5, 1, 3, 2),(2, 2, 3) ) +for ($i = 0; $i -lt $myints.Length; $i++ ) { + write-host "Input: @ints = [",$myints[$i],"]" + + $arr = $myints[$i] + $ln = $arr.Length + $cnt = 0 + $x = 1 + #write-host "len = $ln" + while ($x -lt $ln ) { + write-host -nonewline `t + if ( $arr[$x] -gt $arr[$x-1]) { + write-host $arr[$x] "greater than" $arr[$x-1] + $x += 1 + } elseif ( $arr[$x] -eq $arr[$x-1]) { + write-host $arr[$x] "less than or equal to" $arr[$x-1] + $x += 1 + $cnt += 1 + } else { + write-host $arr[$x] "less than" $arr[$x-1] + $x += 1 + $cnt += 1 + } + } + if ($cnt -eq 1) { + write-host "Output: true"`n + } else { + write-host "Output: false"`n + } +} + +<# +------------------------------------------ +SAMPLE OUTPUT +.\RemoveOne.ps1 + +Input: @ints = [ 0 2 9 4 6 ] + 2 greater than 0 + 9 greater than 2 + 4 less than 9 + 6 greater than 4 +Output: true + +Input: @ints = [ 5 1 3 2 ] + 1 less than 5 + 3 greater than 1 + 2 less than 3 +Output: false + +Input: @ints = [ 2 2 3 ] + 2 less than or equal to 2 + 3 greater than 2 +Output: true +------------------------------------------ +#> + + diff --git a/challenge-235/robert-dicicco/powershell/ch-2.psl b/challenge-235/robert-dicicco/powershell/ch-2.psl new file mode 100644 index 0000000000..2aecb8a9f4 --- /dev/null +++ b/challenge-235/robert-dicicco/powershell/ch-2.psl @@ -0,0 +1,45 @@ +<# +------------------------------------------ +AUTHOR: Robert DiCicco +DATE ; 2023-09-19 +Challenge 235 Task 02 Duplicate Zeroes ( Powershell ) +------------------------------------------ +#> +$myints = @( @(1, 0, 2, 3, 0, 4, 5, 0), + @(1, 2, 3), + @(0, 3, 0, 4, 5) + ) + +for ($i = 0; $i -lt $myints.Length; $i++ ) +{ + $seen = @() + write-host "Input: @ints = [", $myints[$i], "]" + $ln = $myints[$i].Length - 1 + foreach ($x in $myints[$i]) { + if ($x -eq 0) { + $seen += 0 + $seen += 0 + } else { + $seen += $x + } + } + write-host "Output: [",$seen[0..$ln],"]`n" +} + +<# +------------------------------------------ +SAMPLE OUTPUT +.\DuplicateZeros.ps1 + +Input: @ints = [ 1 0 2 3 0 4 5 0 ] +Output: [ 1 0 0 2 3 0 0 4 ] + +Input: @ints = [ 1 2 3 ] +Output: [ 1 2 3 ] + +Input: @ints = [ 0 3 0 4 5 ] +Output: [ 0 0 3 0 0 ] +------------------------------------------ +#> + + diff --git a/challenge-235/robert-dicicco/python/ch-1.py b/challenge-235/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..1da5a82a29 --- /dev/null +++ b/challenge-235/robert-dicicco/python/ch-1.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +''' +--------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-09-18 +Challenge 235 Task 1 Remove One ( Python ) +--------------------------------------- +''' + +myints = [[0, 2, 9, 4, 6],[5, 1, 3, 2],[2, 2, 3]] + +for mints in myints: + print(f"Input: @ints = {mints}") + ln = len(mints) + cnt = 0 + x = 1 + while x < ln: + if mints[x] > mints[x-1]: + print(f"\t{mints[x]} greater than {mints[x-1]}") + x += 1 + elif mints[x] == mints[x-1]: + print(f"\t{mints[x]} equal to {mints[x-1]}") + x += 1 + cnt += 1 + else : + print(f"\t{mints[x]} less than {mints[x-1]}") + x += 1 + cnt += 1 + if cnt == 1: + print("Output: true\n") + else: + print("Output: false\n") + +''' +--------------------------------------- +SAMPLE OUTPUT +python .\RemoveOne.py + +Input: @ints = [0, 2, 9, 4, 6] + 2 greater than 0 + 9 greater than 2 + 4 less than 9 + 6 greater than 4 +Output: true + +Input: @ints = [5, 1, 3, 2] + 1 less than 5 + 3 greater than 1 + 2 less than 3 +Output: false + +Input: @ints = [2, 2, 3] + 2 equal to 2 + 3 greater than 2 +Output: true +--------------------------------------- +''' + + diff --git a/challenge-235/robert-dicicco/python/ch-2.py b/challenge-235/robert-dicicco/python/ch-2.py new file mode 100644 index 0000000000..5e0b7e717e --- /dev/null +++ b/challenge-235/robert-dicicco/python/ch-2.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +''' +------------------------------------------ +AUTHOR: Robert DiCicco +DATE ; 2023-09-18 +Challenge 235 Task 02 Duplicate Zaroes ( Python ) +------------------------------------------ +''' + +myints = [[1, 0, 2, 3, 0, 4, 5, 0],[1, 2, 3],[0, 3, 0, 4, 5]] + +for mints in myints: + print("Input: @ints = ",mints) + seen = [] + ln = len(mints) + for x in mints: + if x == 0: + seen += [0,0] + else: + seen.append(x) + print(f"Output: {seen[0:ln]}\n") + +''' +------------------------------------------ +SAMPLE OUTPUT +python .\DuplicateZeros.py + +Input: @ints = [1, 0, 2, 3, 0, 4, 5, 0] +Output: [1, 0, 0, 2, 3, 0, 0, 4] + +Input: @ints = [1, 2, 3] +Output: [1, 2, 3] + +Input: @ints = [0, 3, 0, 4, 5] +Output: [0, 0, 3, 0, 0] +------------------------------------------ +''' + + diff --git a/challenge-235/robert-dicicco/raku/ch-1.raku b/challenge-235/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..d3fae3473b --- /dev/null +++ b/challenge-235/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,58 @@ +#!/usr/bin/env raku +=begin comment +--------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-09-18 +Challenge 235 Task 1 Remove One ( Raku ) +--------------------------------------- +=end comment +use v6; + +my @myints = ([0, 2, 9, 4, 6],[5, 1, 3, 2],[2, 2, 3]); + +for (@myints) -> @mints { + say "Input: \@ints = ", @mints; + my $len = @mints.elems; + my $cnt = 0; + my $x = 1; + while $x < $len { + if (@mints[$x] > @mints[$x - 1]) { + say "\t@mints[$x] greater than @mints[$x - 1]"; + $x++; + } else { + say "\t@mints[$x] less than @mints[$x - 1]"; + $cnt++; + $x++; + } + } + $cnt == 1 ?? say "Output: true\n" !! say "Output: false\n"; +} + +=begin comment +--------------------------------------- +SAMPLE OUTPUT +raku .\RemoveOne.rk + +Input: @ints = [0 2 9 4 6] + 2 greater than 0 + 9 greater than 2 + 4 less than 9 + 6 greater than 4 +Output: true + +Input: @ints = [5 1 3 2] + 1 less than 5 + 3 greater than 1 + 2 less than 3 +Output: false + +Input: @ints = [2 2 3] + 2 less than 2 + 3 greater than 2 +Output: true +--------------------------------------- +=end comment + + + + diff --git a/challenge-235/robert-dicicco/raku/ch-2.raku b/challenge-235/robert-dicicco/raku/ch-2.raku new file mode 100644 index 0000000000..5665504d08 --- /dev/null +++ b/challenge-235/robert-dicicco/raku/ch-2.raku @@ -0,0 +1,44 @@ +#!/usr/bin/env raku +=begin comment +------------------------------------------ +AUTHOR: Robert DiCicco +DATE ; 2023-09-18 +Challenge 235 Task 02 Duplicate Zaroes ( Raku ) +------------------------------------------ +=end comment +use v6; + +my @myints = ([1, 0, 2, 3, 0, 4, 5, 0],[1, 2, 3],[0, 3, 0, 4, 5]); + +for (@myints) -> @mints { + say "Input: \@ints = ",@mints; + my @seen = (); + my $len = @mints.elems - 1; + for (@mints) -> $x { + if $x != 0 { + @seen.push: $x; + } else { + @seen.push: 0; + @seen.push: 0; + } + } + say "Output: [@seen[0..$len]]\n"; +} + +=begin comment +------------------------------------------ +SAMPLE OUTPUT +raku .\DuplicateZeros.rk + +Input: @ints = [1 0 2 3 0 4 5 0] +Output: [1 0 0 2 3 0 0 4] + +Input: @ints = [1 2 3] +Output: [1 2 3] + +Input: @ints = [0 3 0 4 5] +Output: [0 0 3 0 0] +------------------------------------------ +=end comment + + diff --git a/challenge-235/robert-dicicco/ruby/ch-1.rb b/challenge-235/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..073ad4d012 --- /dev/null +++ b/challenge-235/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,58 @@ +#!/usr/bin/env ruby +=begin +--------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-09-18 +Challenge 235 Task 1 Remove One ( Ruby ) +--------------------------------------- +=end + +myints = [[0, 2, 9, 4, 6],[5, 1, 3, 2],[2, 2, 3]] + +myints.each do |mints| + puts("Input: @ints = #{mints}") + len = mints.length() + cnt = 0 + x = 1 + while x < len + if mints[x] > mints[x-1] + puts("\t#{mints[x]} greater than #{mints[x-1]}") + x += 1 + elsif mints[x] == mints[x-1] + puts("\t#{mints[x]} equal to #{mints[x-1]}") + x += 1 + cnt += 1 + else + puts("\t#{mints[x]} less than #{mints[x-1]}") + x += 1 + cnt += 1 + end + end + cnt == 1 ? puts("Output: true\n\n") : puts("Output: false\n\n") +end + +=begin +--------------------------------------- +SAMPLE OUTPUT +ruby .\RemoveOne.rb +Input: @ints = [0, 2, 9, 4, 6] + 2 greater than 0 + 9 greater than 2 + 4 less than 9 + 6 greater than 4 +Output: true + +Input: @ints = [5, 1, 3, 2] + 1 less than 5 + 3 greater than 1 + 2 less than 3 +Output: false + +Input: @ints = [2, 2, 3] + 2 equal to 2 + 3 greater than 2 +Output: true +--------------------------------------- +=end + + diff --git a/challenge-235/robert-dicicco/ruby/ch-2.rb b/challenge-235/robert-dicicco/ruby/ch-2.rb new file mode 100644 index 0000000000..4a35cbad02 --- /dev/null +++ b/challenge-235/robert-dicicco/ruby/ch-2.rb @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby +=begin comment +------------------------------------------ +AUTHOR: Robert DiCicco +DATE ; 2023-09-18 +Challenge 235 Task 02 Duplicate Zaroes ( Ruby ) +------------------------------------------ +=end comment + +myints = [[1, 0, 2, 3, 0, 4, 5, 0],[1, 2, 3],[0, 3, 0, 4, 5]] + +myints.each do |mints| + puts("Input: @ints = #{mints}") + seen = Array.new + len = mints.length() + mints.each do |x| + if x == 0 + seen.push(0,0) + else + seen.push(x) + end + end + puts("Output: #{seen.slice(0,len)}\n\n") +end + +=begin comment +------------------------------------------ +SAMPLE OUTPUT +ruby .\DuplicateZeros.rb + +Input: @ints = [1, 0, 2, 3, 0, 4, 5, 0] +Output: [1, 0, 0, 2, 3, 0, 0, 4] + +Input: @ints = [1, 2, 3] +Output: [1, 2, 3] + +Input: @ints = [0, 3, 0, 4, 5] +Output: [0, 0, 3, 0, 0] +------------------------------------------ +=end comment + + + + diff --git a/challenge-235/robert-dicicco/tcl/ch-1.tcl b/challenge-235/robert-dicicco/tcl/ch-1.tcl new file mode 100644 index 0000000000..0426a895a9 --- /dev/null +++ b/challenge-235/robert-dicicco/tcl/ch-1.tcl @@ -0,0 +1,64 @@ +#!/usr/bin/env tclsh +set comment { +--------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-09-18 +Challenge 235 Task 1 Remove One ( Tcl ) +--------------------------------------- +} +set myints {{0 2 9 4 6} {5 1 3 2} {2 2 3}} + +foreach ints $myints { + puts "Input: @ints = ($ints)" + set len [llength $ints] + set x 1 + set cnt 0 + while { $x < $len} { + set a [lindex $ints $x] + set b [lindex $ints [expr { $x - 1}]] + if { $a > $b } { + puts "\t$a greater than $b" + set x [expr $x + 1] + } elseif { $a == $b } { + puts "\t$a equal to $b" + set x [expr $x + 1] + set cnt [expr $cnt + 1] + } else { + puts "\t$a less than $b" + set x [expr $x + 1] + set cnt [expr $cnt + 1] + } + } + if { $cnt == 1} { + puts "Output: true\n" + } else { + puts "Output: false\n" + } + } + + set comment { +--------------------------------------- +SAMPLE OUTPUT +tclsh .\RemoveOne.tcl + +Input: @ints = (0 2 9 4 6) + 2 greater than 0 + 9 greater than 2 + 4 less than 9 + 6 greater than 4 +Output: true + +Input: @ints = (5 1 3 2) + 1 less than 5 + 3 greater than 1 + 2 less than 3 +Output: false + +Input: @ints = (2 2 3) + 2 equal to 2 + 3 greater than 2 +Output: true +--------------------------------------- +} + + diff --git a/challenge-235/robert-dicicco/tcl/ch-2.tcl b/challenge-235/robert-dicicco/tcl/ch-2.tcl new file mode 100644 index 0000000000..2928971028 --- /dev/null +++ b/challenge-235/robert-dicicco/tcl/ch-2.tcl @@ -0,0 +1,46 @@ +#!/usr/bin/env tclsh + +set comment { +------------------------------------------ +AUTHOR: Robert DiCicco +DATE ; 2023-09-19 +Challenge 235 Task 02 Duplicate Zaroes ( Tcl ) +------------------------------------------ +} + +set myints {{ 1 0 2 3 0 4 5 0 } { 1 2 3 } { 0 3 0 4 5 }} + +foreach mints $myints { + puts "Input: @ints = ($mints)" + set seen {} + set ln [expr [llength $mints] - 1] + foreach x $mints { + if { $x == 0 } { + lappend seen 0 + lappend seen 0 + } else { + lappend seen $x + } + } + puts -nonewline "Output : (" + puts -nonewline [lrange $seen 0 $ln] + puts ")\n" +} + +set comment { +------------------------------------------ +SAMPLE OUTPUT +tclsh .\DuplicateZeros.tcl + +Input: @ints = ( 1 0 2 3 0 4 5 0 ) +Output : (1 0 0 2 3 0 0 4) + +Input: @ints = ( 1 2 3 ) +Output : (1 2 3) + +Input: @ints = ( 0 3 0 4 5 ) +Output : (0 0 3 0 0) +------------------------------------------ +} + + diff --git a/challenge-235/steven-wilson/python/ch-01.py b/challenge-235/steven-wilson/python/ch-01.py deleted file mode 100644 index 4d5a26bae5..0000000000 --- a/challenge-235/steven-wilson/python/ch-01.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python3 - - -def remove_one(elements): - """removing ONLY one integer makes it strictly increasing order - >>> remove_one( [0, 2, 9, 4, 6] ) - True - >>> remove_one( [5, 1, 3, 2] ) - False - >>> remove_one( [2, 2, 3] ) - True - """ - remove = 0 - for i in range(len(elements) - 1): - if(elements[i] > elements[i+1]): - remove += 1 - if remove == 2: - return False - return True - - -if __name__ == "__main__": - import doctest - - doctest.testmod() diff --git a/challenge-235/steven-wilson/python/ch-02.py b/challenge-235/steven-wilson/python/ch-02.py deleted file mode 100644 index 9a5586206e..0000000000 --- a/challenge-235/steven-wilson/python/ch-02.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python3 - - -def duplicate_zero(elements): - '''duplicate each occurrence of ZERO in the given array and shift - the remaining to the right but make sure the size of array remain - the same - >>> duplicate_zero( [1, 0, 2, 3, 0, 4, 5, 0] ) - [1, 0, 0, 2, 3, 0, 0, 4] - >>> duplicate_zero( [1, 2, 3] ) - [1, 2, 3] - >>> duplicate_zero( [0, 3, 0, 4, 5] ) - [0, 0, 3, 0, 0] - >>> duplicate_zero( [1, 2, 3, 0] ) - [1, 2, 3, 0] - ''' - duplicate_zeroes = [] - elements_length = len(elements) - for i in range(elements_length): - if(elements[i] == 0): - duplicate_zeroes.extend([0,0]) - else: - duplicate_zeroes.append(elements[i]) - if len(duplicate_zeroes) >= elements_length: - break - return duplicate_zeroes[:elements_length] - - -if __name__ == "__main__": - import doctest - - doctest.testmod() diff --git a/challenge-235/steven-wilson/python/ch-1.py b/challenge-235/steven-wilson/python/ch-1.py new file mode 100644 index 0000000000..4d5a26bae5 --- /dev/null +++ b/challenge-235/steven-wilson/python/ch-1.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + + +def remove_one(elements): + """removing ONLY one integer makes it strictly increasing order + >>> remove_one( [0, 2, 9, 4, 6] ) + True + >>> remove_one( [5, 1, 3, 2] ) + False + >>> remove_one( [2, 2, 3] ) + True + """ + remove = 0 + for i in range(len(elements) - 1): + if(elements[i] > elements[i+1]): + remove += 1 + if remove == 2: + return False + return True + + +if __name__ == "__main__": + import doctest + + doctest.testmod() diff --git a/challenge-235/steven-wilson/python/ch-2.py b/challenge-235/steven-wilson/python/ch-2.py new file mode 100644 index 0000000000..9a5586206e --- /dev/null +++ b/challenge-235/steven-wilson/python/ch-2.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + + +def duplicate_zero(elements): + '''duplicate each occurrence of ZERO in the given array and shift + the remaining to the right but make sure the size of array remain + the same + >>> duplicate_zero( [1, 0, 2, 3, 0, 4, 5, 0] ) + [1, 0, 0, 2, 3, 0, 0, 4] + >>> duplicate_zero( [1, 2, 3] ) + [1, 2, 3] + >>> duplicate_zero( [0, 3, 0, 4, 5] ) + [0, 0, 3, 0, 0] + >>> duplicate_zero( [1, 2, 3, 0] ) + [1, 2, 3, 0] + ''' + duplicate_zeroes = [] + elements_length = len(elements) + for i in range(elements_length): + if(elements[i] == 0): + duplicate_zeroes.extend([0,0]) + else: + duplicate_zeroes.append(elements[i]) + if len(duplicate_zeroes) >= elements_length: + break + return duplicate_zeroes[:elements_length] + + +if __name__ == "__main__": + import doctest + + doctest.testmod() diff --git a/challenge-235/ulrich-rieke/cpp/ch-1.cpp b/challenge-235/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..a9ba64a9d0 --- /dev/null +++ b/challenge-235/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + +std::vector split( const std::string & startline , + const std::string & sep ) { + std::vector separated ; + std::string::size_type start { 0 } ; + std::string::size_type pos ; + do { + pos = startline.find_first_of( sep , start ) ; + separated.push_back( startline.substr(start , pos - start )) ; + start = pos + 1 ; + } while ( pos != std::string::npos ) ; + return separated ; +} + +int main( ) { + std::cout << "Enter some integers, separated by spaces!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + std::vector numberstrings( split( line , " " ) ) ; + std::vector numbers ; + for ( auto s : numberstrings ) + numbers.push_back( std::stoi( s ) ) ; + //if size is the length of numbers, we can form size - 1 neighbouring pairs + //they all , bar one, must be strictly increasing + int count = 0 ; //number of strictly increasing neighbouring pairs ; + int pairnumber = numbers.size( ) - 1 ; + for ( int pos = 0 ; pos < numbers.size( ) - 1 ; pos++ ) { + if ( numbers[ pos + 1 ] > numbers[ pos ] ) + count++ ; + } + if ( count == pairnumber - 1 ) + std::cout << "true\n" ; + else + std::cout << "false\n" ; + return 0 ; +} diff --git a/challenge-235/ulrich-rieke/cpp/ch-2.cpp b/challenge-235/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..5bf421ce9c --- /dev/null +++ b/challenge-235/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,41 @@ +#include +#include +#include + +std::vector split( const std::string & startline , + const std::string & sep ) { + std::vector separated ; + std::string::size_type start { 0 } ; + std::string::size_type pos ; + do { + pos = startline.find_first_of( sep , start ) ; + separated.push_back( startline.substr(start , pos - start )) ; + start = pos + 1 ; + } while ( pos != std::string::npos ) ; + return separated ; +} + +int main( ) { + std::cout << "Please enter some integers, separated by spaces!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + std::vector numberstrings( split( line, " " ) ) ; + std::vector numbers ; + for ( auto s : numberstrings ) + numbers.push_back( std::stoi( s ) ) ; + std::vector result ; + for ( int n : numbers ) { + if ( n != 0 ) + result.push_back( n ) ; + else { + result.push_back( 0 ) ; + result.push_back( 0 ) ; + } + } + std::cout << "( " ; + for ( int i = 0 ; i < numbers.size( ) ; i++ ) { + std::cout << result[ i ] << " " ; + } + std::cout << " )\n" ; + return 0 ; +} diff --git a/challenge-235/ulrich-rieke/haskell/ch-1.hs b/challenge-235/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..a186f481cf --- /dev/null +++ b/challenge-235/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,17 @@ +module Challenge235 + where +import Data.List.Split ( divvy ) + +solution :: [Int] -> Bool +solution numbers = (length $ filter (\subli -> last subli > head subli ) pairs) == + pairlength - 1 + where + pairs = divvy 2 1 numbers + pairlength = length pairs + +main :: IO ( ) +main = do + putStrLn "Enter some integers, separated by blanks!" + numberstrings <- getLine + let numbers = map read $ words numberstrings + if solution numbers then putStrLn "true" else putStrLn "false" diff --git a/challenge-235/ulrich-rieke/haskell/ch-2.hs b/challenge-235/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..386baa2aef --- /dev/null +++ b/challenge-235/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,12 @@ +module Challenge235_2 + where + +solution :: [Int] -> [Int] +solution numbers = take ( length numbers ) $ concat $ map (\n -> if n /= 0 then [n] + else replicate 2 n ) numbers + +main :: IO ( ) +main = do + putStrLn "Enter some integers, separated by spaces!" + numberstrings <- getLine + print $ solution $ map read $ words numberstrings diff --git a/challenge-235/ulrich-rieke/perl/ch-1.pl b/challenge-235/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..1152adbe0c --- /dev/null +++ b/challenge-235/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; + +say "Enter some integers, separated by spaces!" ; +my $line = ; +chomp $line ; +my @numbers = split( /\s/ , $line ) ; +my $len = scalar( @numbers ) ; +#we can form $len - 1 pairs of neighbouring pairs. Every one bar one must be strictly +#increasing! +my $pairnumber = $len - 1 ; +my $count = 0 ; #how many neighbouring pairs are strictly increasing? +for my $pos( 0..$len - 2) { + if ( $numbers[ $pos + 1 ] > $numbers[ $pos ] ) { + $count++ ; + } +} +if ( $count == $pairnumber - 1) { + say "true" ; +} +else { + say "false" ; +} diff --git a/challenge-235/ulrich-rieke/perl/ch-2.pl b/challenge-235/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..ee9f85e43c --- /dev/null +++ b/challenge-235/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; + +say "Enter some integers, separated by spaces!" ; +my $line = ; +chomp $line ; +my @numbers = split( /\s/ , $line ) ; +my @result ; +my $len = scalar( @numbers ) ; +for my $n ( @numbers ) { + if ( $n != 0 ) { + push @result , $n ; + } + else { + for (1 , 2 ) { + push @result , 0 ; + } + } +} +say "(" . join( ',' , @result[0..$len - 1] ) . ")" ; diff --git a/challenge-235/ulrich-rieke/raku/ch-1.raku b/challenge-235/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..ad4f2a7b59 --- /dev/null +++ b/challenge-235/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,22 @@ +use v6 ; + +say "Enter some integers, separated by spaces!" ; +my $line = $*IN.get ; +my @numbers = $line.words.map( {.Int} ) ; +my $len = @numbers.elems ; +my $count = 0 ; +for (0..$len - 2) -> $pos { + if ( @numbers[ $pos + 1 ] > @numbers[ $pos ] ) { + $count++ ; + } +} +#if $len is the number of elements we can form $len - 1 neighbouring pairs +#that means that in order to fulfill the condition all neighbouring pairs +#bar 1 must be strictly increasing +my $pairnumber = $len - 1 ; +if ( $count == $pairnumber - 1 ) { + say "true" ; +} +else { + say "false" ; +} diff --git a/challenge-235/ulrich-rieke/raku/ch-2.raku b/challenge-235/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..998f807262 --- /dev/null +++ b/challenge-235/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,18 @@ +use v6 ; + +say "Enter some integers, separated by spaces!" ; +my $line = $*IN.get ; +my @numbers = $line.words.map( {.Int} ) ; +my @result ; +for @numbers -> $n { + if ( $n != 0 ) { + @result.push( $n ) ; + } + else { + for (1 , 2 ) { + @result.push( 0 ) ; + } + } +} +my $len = @numbers.elems ; +say "(" ~ @result[0..$len - 1 ].join( ',' ) ~ ")" ; diff --git a/challenge-235/ulrich-rieke/rust/ch-1.rs b/challenge-235/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..6c015f34f3 --- /dev/null +++ b/challenge-235/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,25 @@ +use std::io ; + +fn main() { + println!("Enter some integers, separated by spaces!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let entered_line : &str = &*inline ; + let numbers : Vec = entered_line.split_whitespace( ).map( | s | + s.trim( ).parse::( ).unwrap( ) ).collect( ) ; + let mut neighbours : Vec<(i32 , i32)> = Vec::new( ) ; + for i in 0..=numbers.len( ) - 2 { + let mut pair : (i32 , i32) = (0 , 0); + pair.0 = numbers[i] ; + let j : usize = i + 1 ; + pair.1 = numbers[ j ] ; + neighbours.push( pair ) ; + } + let len : usize = neighbours.len( ) ; + if neighbours.iter( ).filter( | &p | p.1 > p.0 ).count( ) == len - 1 { + println!("true") ; + } + else { + println!("false") ; + } +} diff --git a/challenge-235/ulrich-rieke/rust/ch-2.rs b/challenge-235/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..f8454a1dfd --- /dev/null +++ b/challenge-235/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,25 @@ +use std::io ; + +fn main() { + println!("Enter some integers, separated by spaces!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let entered_line : &str = &*inline ; + let numbers : Vec = entered_line.split_whitespace( ).map( | s | + s.trim( ).parse::( ).unwrap( ) ).collect( ) ; + let len = numbers.len( ) ; + let mut result : Vec = Vec::new( ) ; + for i in &numbers { + if *i != 0 { + result.push( *i ) ; + } + else { + for _ in 0..2 { + result.push( 0 ) ; + } + } + } + let result_slice = &result[0..len] ; + let result = result_slice.to_vec( ) ; + println!("{:?}" , result ) ; +} diff --git a/stats/pwc-challenge-234.json b/stats/pwc-challenge-234.json new file mode 100644 index 0000000000..45578863db --- /dev/null +++ b/stats/pwc-challenge-234.json @@ -0,0 +1,669 @@ +{ + "drilldown" : { + "series" : [ + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Ali Moradi", + "name" : "Ali Moradi" + }, + { + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Arne Sommer", + "id" : "Arne Sommer" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Athanasius", + "name" : "Athanasius" + }, + { + "name" : "Avery Adams", + "id" : "Avery Adams", + "data" : [ + [ + "Perl", + 1 + ], + [ + "Blog", + 2 + ] + ] + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "name" : "BarrOff", + "id" : "BarrOff" + }, + { + "name" : "Bob Lied", + "id" : "Bob Lied", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "id" : "Bruce Gray", + "name" : "Bruce Gray", + "data" : [ + [ + "Raku", + 2 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Cheok-Yin Fung", + "name" : "Cheok-Yin Fung" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Dave Jacoby", + "name" : "Dave Jacoby" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "David Ferrone", + "name" : "David Ferrone" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "E. Choroba", + "name" : "E. Choroba" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Humberto Massa", + "name" : "Humberto Massa" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "name" : "Jan Krnavek", + "id" : "Jan Krnavek" + }, + { + "id" : "Jorg Sommrey", + "name" : "Jorg Sommrey", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 1 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Laurent Rosenfeld", + "name" : "Laurent Rosenfeld" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Lubos Kolouch", + "id" : "Lubos Kolouch" + }, + { + "id" : "Luca Ferrari", + "name" : "Luca Ferrari", + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 6 + ] + ] + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "name" : "Mark Anderson", + "id" : "Mark Anderson" + }, + { + "name" : "Matthew Neleigh", + "id" : "Matthew Neleigh", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "id" : "Matthias Muth", + "name" : "Matthias Muth", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "Niels van Dijke", + "id" : "Niels van Dijke" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Packy Anderson", + "name" : "Packy Anderson" + }, + { + "id" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "Peter Meszaros", + "id" : "Peter Meszaros" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "rcmlz", + "name" : "rcmlz" + }, + { + "id" : "Robbie Hatley", + "name" : "Robbie Hatley", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "name" : "Robert DiCicco", + "id" : "Robert DiCicco", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ] + }, + { + "id" : "Robert Ransbottom", + "name" : "Robert Ransbottom", + "data" : [ + [ + "Raku", + 2 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Roger Bell_West", + "id" : "Roger Bell_West" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "Simon Green", + "id" : "Simon Green" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Solathian", + "name" : "Solathian" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Stephen G. Lynn", + "name" : "Stephen G. Lynn" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 2 + ] + ], + "name" : "Thomas Kohler", + "id" : "Thomas Kohler" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 +