From 6045029f14b82441b83c2a5649398d8cb5be7ad2 Mon Sep 17 00:00:00 2001 From: Bob Lied Date: Mon, 18 Sep 2023 09:46:29 -0500 Subject: Update README for week 235 --- challenge-235/bob-lied/README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/challenge-235/bob-lied/README b/challenge-235/bob-lied/README index 260e5988c9..078b56c84e 100644 --- a/challenge-235/bob-lied/README +++ b/challenge-235/bob-lied/README @@ -1,4 +1,4 @@ -Solutions to weekly challenge 234 by Bob Lied +Solutions to weekly challenge 235 by Bob Lied -https://perlweeklychallenge.org/blog/perl-weekly-challenge-234/ -https://github.com/boblied/perlweeklychallenge-club/tree/master/challenge-234/bob-lied +https://perlweeklychallenge.org/blog/perl-weekly-challenge-235/ +https://github.com/boblied/perlweeklychallenge-club/tree/master/challenge-235/bob-lied -- cgit From cf0d06f9fb5b80165ef5a59c3537ce9763b4abbc Mon Sep 17 00:00:00 2001 From: Bob Lied Date: Mon, 18 Sep 2023 09:46:50 -0500 Subject: Week 235 Task 1 solution --- challenge-235/bob-lied/perl/ch-1.pl | 100 ++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 challenge-235/bob-lied/perl/ch-1.pl diff --git a/challenge-235/bob-lied/perl/ch-1.pl b/challenge-235/bob-lied/perl/ch-1.pl new file mode 100644 index 0000000000..10b33b72be --- /dev/null +++ b/challenge-235/bob-lied/perl/ch-1.pl @@ -0,0 +1,100 @@ +#!/usr/bin/env perl +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# ch-1.pl Perl Weekly Challenge 235 Task 1 Remove One +#============================================================================= +# Copyright (c) 2023, Bob Lied +#============================================================================= +# You are given an array of integers. +# Write a script to find out if removing ONLY one integer makes it +# strictly kincreasing order. +# Example 1 Input: @ints = (0, 2, 9, 4, 6) +# Output: true +# Removing ONLY 9 in the given array makes it strictly increasing order. +# Example 2 Input: @ints = (5, 1, 3, 2) +# Output: false +# Example 3 Input: @ints = (2, 2, 3) +# Output: true +#============================================================================= + +use v5.38; +use builtin qw(true false); no warnings "experimental::builtin"; + +use Getopt::Long; +my $Verbose = 0; +my $DoTest = 0; + +GetOptions("test" => \$DoTest, "verbose" => \$Verbose); +exit(!runTest()) if $DoTest; + +# Move down the list in pairs and count the number of times that +# we find a decreasing pair. Stop when we hit the second one. +sub removeOne(@ints) +{ + my $rmvCount = 0; + for ( my $i = 0; $i < $#ints && $rmvCount < 2 ; $i++ ) + { + $rmvCount++ if $ints[$i+1] < $ints[$i]; + } + return $rmvCount < 2; +} + +# Map each pair to true/false for being sorteed ascending. Count the falses. +# Will be inefficient if the list is long and the out-of-order elements are +# near the front. +sub ro_A(@ints) +{ + my $rmvCount = grep { $_ == false } map { $ints[$_] < $ints[$_+1] } 0 .. ( $#ints-1 ); + return $rmvCount < 2; +} + +# Slide down the list in pairs and count the number of items that +# are out of order. Always scans the whole list. +sub ro_B(@ints) +{ + use List::MoreUtils qw/slide/; + my $rmvCount = 0; + slide { $rmvCount++ if ( $b < $a ) } @ints; + return $rmvCount < 2; +} + +# Use try/catch to quit early from slide +sub ro_C(@ints) +{ + use List::MoreUtils qw/slide/; + use feature 'try'; no warnings "experimental::try"; + my $rmvOne = true; + try { + my $rmvCount = 0; + slide { do { die if ++$rmvCount > 1 } if ( $b < $a ) } @ints; + } + catch ($e) + { + $rmvOne = false; + } + return $rmvOne; +} + +sub runTest +{ + use Test2::V0; + no warnings "experimental::builtin"; + + is( removeOne(0,2.9,4,6), true, "Example 1"); + is( removeOne(5,1,3,2 ), false, "Example 2"); + is( removeOne(2,2,3 ), true, "Example 3"); + + is( ro_A(0,2.9,4,6), true, "Example 1"); + is( ro_A(5,1,3,2 ), false, "Example 2"); + is( ro_A(2,2,3 ), true, "Example 3"); + + is( ro_B(0,2.9,4,6), true, "Example 1"); + is( ro_B(5,1,3,2 ), false, "Example 2"); + is( ro_B(2,2,3 ), true, "Example 3"); + + is( ro_C(0,2.9,4,6), true, "Example 1"); + is( ro_C(5,1,3,2 ), false, "Example 2"); + is( ro_C(2,2,3 ), true, "Example 3"); + + done_testing; +} -- cgit From abc5d51f65ffafb1be1919668984f50335915c6c Mon Sep 17 00:00:00 2001 From: Bob Lied Date: Mon, 18 Sep 2023 10:09:01 -0500 Subject: Week 235 Task 2 solution --- challenge-235/bob-lied/perl/ch-2.pl | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 challenge-235/bob-lied/perl/ch-2.pl diff --git a/challenge-235/bob-lied/perl/ch-2.pl b/challenge-235/bob-lied/perl/ch-2.pl new file mode 100644 index 0000000000..1c2b6ac1b1 --- /dev/null +++ b/challenge-235/bob-lied/perl/ch-2.pl @@ -0,0 +1,66 @@ +#!/usr/bin/env perl +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# ch-2.pl Perl Weekly Challenge 235 Task 2 Duplicate Zeros +#============================================================================= +# Copyright (c) 2023, Bob Lied +#============================================================================= +# 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. +# Example 1 Input: @ints = (1, 0, 2, 3, 0, 4, 5, 0) +# Ouput: (1, 0, 0, 2, 3, 0, 0, 4) +# Example 2 Input: @ints = (1, 2, 3) +# Ouput: (1, 2, 3) +# Example 3 Input: @ints = (0, 3, 0, 4, 5) +# Ouput: (0, 0, 3, 0, 0) +#============================================================================= + +use v5.36; + +use FindBin qw($Bin); +use lib "$FindBin::Bin"; + +use Getopt::Long; +my $Verbose = 0; +my $DoTest = 0; + +GetOptions("test" => \$DoTest, "verbose" => \$Verbose); +exit(!runTest()) if $DoTest; + +sub duplicateZeros(@ints) +{ + [ (map { $_ || (0,0) } @ints)[0 .. $#ints] ] +} + +sub dz_A(@ints) +{ + my $maxLen = @ints; + my @output; + while ( @output < $maxLen ) + { + push @output, shift @ints; + push @output, 0 if ( $output[-1] == 0 && @output < $maxLen ); + } + return \@output; +} + +sub runTest +{ + use Test2::V0; + + is( duplicateZeros(1,0,2,3,0,4,5,0), [1,0,0,2,3,0,0,4], "Example 1"); + is( duplicateZeros(1,2,3 ), [1,2,3 ], "Example 2"); + is( duplicateZeros(0,3,0,4,5 ), [0,0,3,0,0 ], "Example 3"); + is( duplicateZeros(0), [0], "One Zero"); + is( duplicateZeros(2, 1, 0), [2, 1, 0], "Ends on a zero"); + + is( dz_A(1,0,2,3,0,4,5,0), [1,0,0,2,3,0,0,4], "Example 1"); + is( dz_A(1,2,3 ), [1,2,3 ], "Example 2"); + is( dz_A(0,3,0,4,5 ), [0,0,3,0,0 ], "Example 3"); + is( dz_A(0), [0], "One Zero"); + is( dz_A(2, 1, 0), [2, 1, 0], "Ends on a zero"); + + done_testing; +} -- cgit From d5c84ed05f7d37a00dbb6a9b48dd598511e9dc50 Mon Sep 17 00:00:00 2001 From: Bob Lied Date: Mon, 18 Sep 2023 10:09:33 -0500 Subject: Week 235 Task 1 solution --- challenge-235/bob-lied/perl/ch-1.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/challenge-235/bob-lied/perl/ch-1.pl b/challenge-235/bob-lied/perl/ch-1.pl index 10b33b72be..06ce8fe5cf 100644 --- a/challenge-235/bob-lied/perl/ch-1.pl +++ b/challenge-235/bob-lied/perl/ch-1.pl @@ -39,12 +39,13 @@ sub removeOne(@ints) return $rmvCount < 2; } -# Map each pair to true/false for being sorteed ascending. Count the falses. +# Map each pair to true/false for being sorted ascending. Count the falses. # Will be inefficient if the list is long and the out-of-order elements are # near the front. sub ro_A(@ints) { - my $rmvCount = grep { $_ == false } map { $ints[$_] < $ints[$_+1] } 0 .. ( $#ints-1 ); + my $rmvCount = grep { $_ == false } + map { $ints[$_] < $ints[$_+1] } 0 .. ( $#ints-1 ); return $rmvCount < 2; } -- cgit From ae4497b916f9a1bb55833a736306764284f2d7fe Mon Sep 17 00:00:00 2001 From: "Jaldhar H. Vyas" Date: Mon, 18 Sep 2023 18:55:45 -0400 Subject: Challenge-234 by Jaldhar H. Vyas. --- challenge-234/jaldhar-h-vyas/blog.txt | 1 + challenge-234/jaldhar-h-vyas/perl/ch-1.pl | 40 +++++++++++++++++++++++++++++ challenge-234/jaldhar-h-vyas/perl/ch-2.pl | 35 +++++++++++++++++++++++++ challenge-234/jaldhar-h-vyas/raku/ch-1.sh | 3 +++ challenge-234/jaldhar-h-vyas/raku/ch-2.raku | 15 +++++++++++ 5 files changed, 94 insertions(+) create mode 100644 challenge-234/jaldhar-h-vyas/blog.txt create mode 100755 challenge-234/jaldhar-h-vyas/perl/ch-1.pl create mode 100755 challenge-234/jaldhar-h-vyas/perl/ch-2.pl create mode 100755 challenge-234/jaldhar-h-vyas/raku/ch-1.sh create mode 100755 challenge-234/jaldhar-h-vyas/raku/ch-2.raku diff --git a/challenge-234/jaldhar-h-vyas/blog.txt b/challenge-234/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..3491d9fbb9 --- /dev/null +++ b/challenge-234/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2023/09/perl_weekly_challenge_week_234.html diff --git a/challenge-234/jaldhar-h-vyas/perl/ch-1.pl b/challenge-234/jaldhar-h-vyas/perl/ch-1.pl new file mode 100755 index 0000000000..8fa5006f3f --- /dev/null +++ b/challenge-234/jaldhar-h-vyas/perl/ch-1.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +sub distinct { + my ($arr) = @_; + my %unique; + my @distinct; + + for my $elem (@{$arr}) { + $unique{$elem}++; + push @distinct, "$elem$unique{$elem}"; + } + + return @distinct; +} + +sub intersection { + my @sets = @_; + my %count; + + for my $set (@sets) { + for my $elem (distinct($set)) { + if (!exists $count{$elem}) { + $count{$elem} = 1; + } else { + $count{$elem}++; + } + } + } + + return [ map { [split //, $_]->[0] } grep { $_ if $count{$_} == scalar @sets } keys %count ]; +} + +my @words = map { [ split //, $_ ] } @ARGV; + +say + q{(}, + ( join q{, }, map { "\"$_\"" } ( sort @{intersection( @words )} ) ), + q{)}; diff --git a/challenge-234/jaldhar-h-vyas/perl/ch-2.pl b/challenge-234/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..29204d827f --- /dev/null +++ b/challenge-234/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +sub combinations { + my @list = @{$_[0]}; + my $length = $_[1]; + + if ($length <= 1) { + return map [$_], @list; + } + + my @combos; + + for (my $i = 0; $i + $length <= scalar @list; $i++) { + my $val = $list[$i]; + my @rest = @list[$i + 1 .. $#list]; + for my $c (combinations(\@rest, $length - 1)) { + push @combos, [$val, @{$c}] ; + } + } + + return @combos; +} + +my %ints; + +while (my ($key, $value) = each @ARGV) { + $ints{$key} = $value; +} + +say scalar grep { + my ($i, $j, $k) = map { $ints{$_} } @{$_}; + $i != $j && $j != $k && $k != $i; +} combinations([keys %ints], 3); diff --git a/challenge-234/jaldhar-h-vyas/raku/ch-1.sh b/challenge-234/jaldhar-h-vyas/raku/ch-1.sh new file mode 100755 index 0000000000..106ca4032e --- /dev/null +++ b/challenge-234/jaldhar-h-vyas/raku/ch-1.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +raku -e 'say q{(},([∩] @*ARGS.map({$_.comb.BagHash})).map({|($_.key x $_.value).comb}).sort.map({"\"$_\""}).join(q{, }),q{)}' "$@" diff --git a/challenge-234/jaldhar-h-vyas/raku/ch-2.raku b/challenge-234/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..f4a0ae9e7b --- /dev/null +++ b/challenge-234/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,15 @@ +#!/usr/bin/raku + +sub MAIN( + *@ints +) { + @ints + .keys + .combinations(3) + .grep({ + my ($i, $j, $k) = @$_.map({ @ints[$_] }); + $i != $j && $j != $k && $k != $i; + }) + .elems + .say; +} \ No newline at end of file -- cgit From 638dd0ea627d7094f534288d634abc5fc8ecb56d Mon Sep 17 00:00:00 2001 From: Asher Harvey-Smith Date: Wed, 20 Sep 2023 11:18:27 +0100 Subject: challenge 235 solutions --- challenge-235/asherbhs/README | 1 + challenge-235/asherbhs/apl/ch-1.apl | 7 +++++++ challenge-235/asherbhs/apl/ch-2.apl | 7 +++++++ challenge-235/asherbhs/bqn/ch-1.bqn | 7 +++++++ challenge-235/asherbhs/bqn/ch-2.bqn | 7 +++++++ challenge-235/asherbhs/haskell/ch-1.hs | 17 +++++++++++++++++ challenge-235/asherbhs/haskell/ch-2.hs | 14 ++++++++++++++ challenge-235/asherbhs/j/ch-1.ijs | 9 +++++++++ challenge-235/asherbhs/j/ch-2.ijs | 9 +++++++++ 9 files changed, 78 insertions(+) create mode 100644 challenge-235/asherbhs/README create mode 100755 challenge-235/asherbhs/apl/ch-1.apl create mode 100755 challenge-235/asherbhs/apl/ch-2.apl create mode 100755 challenge-235/asherbhs/bqn/ch-1.bqn create mode 100755 challenge-235/asherbhs/bqn/ch-2.bqn create mode 100755 challenge-235/asherbhs/haskell/ch-1.hs create mode 100755 challenge-235/asherbhs/haskell/ch-2.hs create mode 100755 challenge-235/asherbhs/j/ch-1.ijs create mode 100755 challenge-235/asherbhs/j/ch-2.ijs diff --git a/challenge-235/asherbhs/README b/challenge-235/asherbhs/README new file mode 100644 index 0000000000..5c37138bd7 --- /dev/null +++ b/challenge-235/asherbhs/README @@ -0,0 +1 @@ +Solutions by Asher Harvey-Smith diff --git a/challenge-235/asherbhs/apl/ch-1.apl b/challenge-235/asherbhs/apl/ch-1.apl new file mode 100755 index 0000000000..dffb4048be --- /dev/null +++ b/challenge-235/asherbhs/apl/ch-1.apl @@ -0,0 +1,7 @@ +#!/usr/bin/env dyalogscript + +RemoveOne←{∨/∧/2 Bool +removeOne xs = or $ map + (\n -> + let + xs' = take n xs ++ drop (n+1) xs + in + and $ zipWith (<) xs' $ tail xs' + ) + [0..length xs - 1] + +main :: IO () +main = do + print $ removeOne [0, 2, 9, 4, 6] + print $ removeOne [5, 1, 3, 2] + print $ removeOne [2, 2, 3] diff --git a/challenge-235/asherbhs/haskell/ch-2.hs b/challenge-235/asherbhs/haskell/ch-2.hs new file mode 100755 index 0000000000..b36a382e9d --- /dev/null +++ b/challenge-235/asherbhs/haskell/ch-2.hs @@ -0,0 +1,14 @@ +#!/usr/bin/env runhaskell + +duplicateZeros :: [Int] -> [Int] +duplicateZeros xs = take (length xs) $ dup xs + where + dup [] = [] + dup (0 : xs) = 0 : 0 : dup xs + dup (x : xs) = x : dup xs + +main :: IO () +main = do + print $ duplicateZeros [1, 0, 2, 3, 0, 4, 5, 0] + print $ duplicateZeros [1, 2, 3] + print $ duplicateZeros [0, 3, 0, 4, 5] diff --git a/challenge-235/asherbhs/j/ch-1.ijs b/challenge-235/asherbhs/j/ch-1.ijs new file mode 100755 index 0000000000..88b1a788d1 --- /dev/null +++ b/challenge-235/asherbhs/j/ch-1.ijs @@ -0,0 +1,9 @@ +#!/usr/bin/env jconsole + +RemoveOne=:{{+./([:*./2 Date: Wed, 20 Sep 2023 07:50:08 -0500 Subject: Refinements and blog reference --- challenge-235/bob-lied/blog.txt | 1 + challenge-235/bob-lied/perl/ch-1.pl | 89 +++++++++++++++++++++++++++---------- challenge-235/bob-lied/perl/ch-2.pl | 20 +++++++++ 3 files changed, 86 insertions(+), 24 deletions(-) create mode 100644 challenge-235/bob-lied/blog.txt diff --git a/challenge-235/bob-lied/blog.txt b/challenge-235/bob-lied/blog.txt new file mode 100644 index 0000000000..db7e36a16c --- /dev/null +++ b/challenge-235/bob-lied/blog.txt @@ -0,0 +1 @@ +https://dev.to/boblied/pwc-235-steppin-in-a-slide-zone-la6 diff --git a/challenge-235/bob-lied/perl/ch-1.pl b/challenge-235/bob-lied/perl/ch-1.pl index 06ce8fe5cf..76a280fae6 100644 --- a/challenge-235/bob-lied/perl/ch-1.pl +++ b/challenge-235/bob-lied/perl/ch-1.pl @@ -27,9 +27,73 @@ my $DoTest = 0; GetOptions("test" => \$DoTest, "verbose" => \$Verbose); exit(!runTest()) if $DoTest; +sub removeOne(@ints) +{ + use List::Util qw/min/; + + return true if @ints < 3; + + my $rmvCount = 0; + + # Walk forward until we hit a descending step. + for ( my $i = 0 ; $i < $#ints && $rmvCount < 2 ; $i++ ) + { + next if $ints[$i+1] >= $ints[$i]; + + # How far backward would we have to go to get back in order? + my $back = 0; + for ( my $j = $i ; $j >= 0 && $ints[$j] > $ints[$i+1] && $back < 3; $j-- ) + { + $back++; + } + + # How far ahead would we have to go to get back in order? + my $ahead = 0; + for ( my $j = $i+1; $j <= $#ints && $ints[$j] <= $ints[$i] && $ahead < 3; $j++ ) + { + $ahead++; + } + $rmvCount += min($back, $ahead); + + } + return $rmvCount < 2; +} + +sub runTest +{ + use Test2::V0; + no warnings "experimental::builtin"; + + is( removeOne(0,2,9,4,6), true, "Example 1"); + is( removeOne(5,1,3,2 ), false, "Example 2"); + is( removeOne(2,2,3 ), true, "Example 3"); + is( removeOne(10,1,2,3 ), true, "First element goes"); + is( removeOne(10,11,1 ), true, "Last element goes"); + is( removeOne(10,20,30,24,25,40), true, "One high peak"); + is( removeOne(10,20,30,18,25,40), false, "One high, one low"); + is( removeOne(1,2,5,3,4,6,3,4), false, "Multiple disorders"); + is( removeOne(99, 1000, 1..999, 2000), false, "Long failure"); + + # is( ro_A(0,2.9,4,6), true, "Example 1"); + # is( ro_A(5,1,3,2 ), false, "Example 2"); + # is( ro_A(2,2,3 ), true, "Example 3"); + + # is( ro_B(0,2.9,4,6), true, "Example 1"); + # is( ro_B(5,1,3,2 ), false, "Example 2"); + # is( ro_B(2,2,3 ), true, "Example 3"); + + # is( ro_C(0,2.9,4,6), true, "Example 1"); + # is( ro_C(5,1,3,2 ), false, "Example 2"); + # is( ro_C(2,2,3 ), true, "Example 3"); + + done_testing; +} + +# Things that don't work. + # Move down the list in pairs and count the number of times that # we find a decreasing pair. Stop when we hit the second one. -sub removeOne(@ints) +sub ro_D(@ints) { my $rmvCount = 0; for ( my $i = 0; $i < $#ints && $rmvCount < 2 ; $i++ ) @@ -76,26 +140,3 @@ sub ro_C(@ints) return $rmvOne; } -sub runTest -{ - use Test2::V0; - no warnings "experimental::builtin"; - - is( removeOne(0,2.9,4,6), true, "Example 1"); - is( removeOne(5,1,3,2 ), false, "Example 2"); - is( removeOne(2,2,3 ), true, "Example 3"); - - is( ro_A(0,2.9,4,6), true, "Example 1"); - is( ro_A(5,1,3,2 ), false, "Example 2"); - is( ro_A(2,2,3 ), true, "Example 3"); - - is( ro_B(0,2.9,4,6), true, "Example 1"); - is( ro_B(5,1,3,2 ), false, "Example 2"); - is( ro_B(2,2,3 ), true, "Example 3"); - - is( ro_C(0,2.9,4,6), true, "Example 1"); - is( ro_C(5,1,3,2 ), false, "Example 2"); - is( ro_C(2,2,3 ), true, "Example 3"); - - done_testing; -} diff --git a/challenge-235/bob-lied/perl/ch-2.pl b/challenge-235/bob-lied/perl/ch-2.pl index 1c2b6ac1b1..0a7b0febf7 100644 --- a/challenge-235/bob-lied/perl/ch-2.pl +++ b/challenge-235/bob-lied/perl/ch-2.pl @@ -46,6 +46,20 @@ sub dz_A(@ints) return \@output; } +sub dz_B(@ints) +{ + for (my $i = 0 ; $i <= $#ints; $i++ ) + { + if ( $ints[$i] == 0 ) + { + # Insert a zero and advance i past it + splice(@ints, $i++, 0, 0); + pop @ints; # Maintain the length; + } + } + return \@ints; +} + sub runTest { use Test2::V0; @@ -62,5 +76,11 @@ sub runTest is( dz_A(0), [0], "One Zero"); is( dz_A(2, 1, 0), [2, 1, 0], "Ends on a zero"); + is( dz_B(1,0,2,3,0,4,5,0), [1,0,0,2,3,0,0,4], "Example 1"); + is( dz_B(1,2,3 ), [1,2,3 ], "Example 2"); + is( dz_B(0,3,0,4,5 ), [0,0,3,0,0 ], "Example 3"); + is( dz_B(0), [0], "One Zero"); + is( dz_B(2, 1, 0), [2, 1, 0], "Ends on a zero"); + done_testing; } -- cgit 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 -