diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2023-05-01 12:01:02 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2023-05-01 12:01:02 +0000 |
| commit | 35a99f991daa099dd4b2b58e83736752ee4d0cf0 (patch) | |
| tree | b11bb4a5157ac3ea5be945756413610f5e30287f | |
| parent | 6cc2e38f43011f65d7deaf1e03cf55e4306a53e5 (diff) | |
| download | perlweeklychallenge-club-35a99f991daa099dd4b2b58e83736752ee4d0cf0.tar.gz perlweeklychallenge-club-35a99f991daa099dd4b2b58e83736752ee4d0cf0.tar.bz2 perlweeklychallenge-club-35a99f991daa099dd4b2b58e83736752ee4d0cf0.zip | |
w215 - Task 1 & 2
| -rwxr-xr-x | challenge-215/perlboy1967/perl/ch1.pl | 35 | ||||
| -rwxr-xr-x | challenge-215/perlboy1967/perl/ch2.pl | 41 |
2 files changed, 76 insertions, 0 deletions
diff --git a/challenge-215/perlboy1967/perl/ch1.pl b/challenge-215/perlboy1967/perl/ch1.pl new file mode 100755 index 0000000000..e89225cda1 --- /dev/null +++ b/challenge-215/perlboy1967/perl/ch1.pl @@ -0,0 +1,35 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 215 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-215 + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Odd one Out +Submitted by: Mohammad S Anwar + +You are given a list of words (alphabetic characters only) of same size. + +Write a script to remove all words not sorted alphabetically and print the number +of words in the list that are not alphabetically sorted. + +=cut + +use v5.16; + +use common::sense; + +use Test::More; + +sub oddOneOut { + grep { $_ ne join '',sort split //,$_ } @_; +} + +is(oddOneOut('abc','xyz','tsu'),1); +is(oddOneOut('rat','cab','dad'),3); +is(oddOneOut('x','y','z'),0); +is(oddOneOut('cd','add','loop'),0); + +done_testing; diff --git a/challenge-215/perlboy1967/perl/ch2.pl b/challenge-215/perlboy1967/perl/ch2.pl new file mode 100755 index 0000000000..45f60ba88d --- /dev/null +++ b/challenge-215/perlboy1967/perl/ch2.pl @@ -0,0 +1,41 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 215 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-215 + +Task 2: Number Placement +Submitted by: Mohammad S Anwar + +You are given a list of numbers having just 0 and 1. You are also given placement count (>=1). + +Write a script to find out if it is possible to replace 0 with 1 in the given list. The only +condition is that you can only replace when there is no 1 on either side. Print 1 if it is +possible otherwise 0. + +=cut + +use v5.16; + +use common::sense; + +use Test::More; + +sub numberPlacement ($@) { + my ($n,$s) = (shift @_,join '',@_); + + $n-- while ($s =~ s#000#010#); + + $n == 0 ? 1 : 0; +} + +is(numberPlacement(1,1,0,0,0,1),1); +is(numberPlacement(2,1,0,0,0,1),0); +is(numberPlacement(3,1,0,0,0,0,0,0,0,1),1); +is(numberPlacement(1),0); +is(numberPlacement(1,0),0); +is(numberPlacement(1,0,0),0); +is(numberPlacement(1,0,0,0),1); + +done_testing; |
