diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-09-20 15:45:30 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-09-20 15:45:30 +0100 |
| commit | 079976d9baaf0bfcc174a1465bc9f693f2630ae4 (patch) | |
| tree | 4b6e0b9350d4f74e00a91bed4709c0b3393a2b07 | |
| parent | 676db478eb13602d1038b376f74c9a0174920e77 (diff) | |
| download | perlweeklychallenge-club-079976d9baaf0bfcc174a1465bc9f693f2630ae4.tar.gz perlweeklychallenge-club-079976d9baaf0bfcc174a1465bc9f693f2630ae4.tar.bz2 perlweeklychallenge-club-079976d9baaf0bfcc174a1465bc9f693f2630ae4.zip | |
- 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.
56 files changed, 4464 insertions, 2955 deletions
diff --git a/challenge-234/perlboy1967/perl/ch1.pl b/challenge-234/perlboy1967/perl/ch-1.pl index d0af0306ce..d0af0306ce 100755 --- a/challenge-234/perlboy1967/perl/ch1.pl +++ b/challenge-234/perlboy1967/perl/ch-1.pl diff --git a/challenge-234/perlboy1967/perl/ch2.pl b/challenge-234/perlboy1967/perl/ch-2.pl index 6c937c1726..6c937c1726 100755 --- a/challenge-234/perlboy1967/perl/ch2.pl +++ b/challenge-234/perlboy1967/perl/ch-2.pl diff --git a/challenge-235/conor-hoekstra/ch-01.bqn b/challenge-235/conor-hoekstra/bqn/ch-1.bqn index 947466daf6..947466daf6 100644 --- a/challenge-235/conor-hoekstra/ch-01.bqn +++ b/challenge-235/conor-hoekstra/bqn/ch-1.bqn diff --git a/challenge-235/conor-hoekstra/ch-02.bqn b/challenge-235/conor-hoekstra/bqn/ch-2.bqn index 3058709816..3058709816 100644 --- a/challenge-235/conor-hoekstra/ch-02.bqn +++ b/challenge-235/conor-hoekstra/bqn/ch-2.bqn 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/ch1.pl b/challenge-235/perlboy1967/perl/ch-1.pl index 568f809937..568f809937 100755 --- a/challenge-235/perlboy1967/perl/ch1.pl +++ b/challenge-235/perlboy1967/perl/ch-1.pl diff --git a/challenge-235/perlboy1967/perl/ch2.pl b/challenge-235/perlboy1967/perl/ch-2.pl index bd9b273777..bd9b273777 100755 --- a/challenge-235/perlboy1967/perl/ch2.pl +++ b/challenge-235/perlboy1967/perl/ch-2.pl 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) |
