diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-01-07 18:24:37 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-07 18:24:37 +0000 |
| commit | 3d5ebd43f8d969586b39553a116f183f687637c0 (patch) | |
| tree | 2e9c9da892a15dd18280a90be090b4034b38fef9 | |
| parent | 8e30607364f6abdd2250591c032126e3e68fdaba (diff) | |
| parent | 70a6662428f2c7982de421eb63bfccf6100939b7 (diff) | |
| download | perlweeklychallenge-club-3d5ebd43f8d969586b39553a116f183f687637c0.tar.gz perlweeklychallenge-club-3d5ebd43f8d969586b39553a116f183f687637c0.tar.bz2 perlweeklychallenge-club-3d5ebd43f8d969586b39553a116f183f687637c0.zip | |
Merge pull request #1117 from choroba/ech042
Add solution to 042 by E. Choroba
| -rwxr-xr-x | challenge-042/e-choroba/perl5/ch-1.pl | 6 | ||||
| -rwxr-xr-x | challenge-042/e-choroba/perl5/ch-2.pl | 24 |
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-042/e-choroba/perl5/ch-1.pl b/challenge-042/e-choroba/perl5/ch-1.pl new file mode 100755 index 0000000000..d7c8ce7340 --- /dev/null +++ b/challenge-042/e-choroba/perl5/ch-1.pl @@ -0,0 +1,6 @@ +#!/usr/bin/perl +use warnings; +use strict; + +printf "Decimal %d = Octal %o\n", $_, $_ + for 0 .. 50; diff --git a/challenge-042/e-choroba/perl5/ch-2.pl b/challenge-042/e-choroba/perl5/ch-2.pl new file mode 100755 index 0000000000..9ab8cd3680 --- /dev/null +++ b/challenge-042/e-choroba/perl5/ch-2.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl +use warnings; +use strict; +use feature qw{ say }; + +sub generate { + return join "", map +('(', ')')[rand 2], 1 .. int rand 80 +} + +sub is_valid { + my ($s) = @_; + $s =~ s/\(\)//g while -1 != index $s, '()'; + return ! length $s +} + + +use Test::More tests => 4; +ok(is_valid('()')); +ok(is_valid('(())')); +ok(! is_valid(')(')); +ok(! is_valid('())()')); + +my $s = generate(); +say $s, ' ', is_valid($s) ? "" : 'in', 'valid'; |
