aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE. Choroba <choroba@matfyz.cz>2020-01-07 18:49:30 +0100
committerE. Choroba <choroba@matfyz.cz>2020-01-07 18:49:30 +0100
commit70a6662428f2c7982de421eb63bfccf6100939b7 (patch)
tree2e9c9da892a15dd18280a90be090b4034b38fef9
parent8e30607364f6abdd2250591c032126e3e68fdaba (diff)
downloadperlweeklychallenge-club-70a6662428f2c7982de421eb63bfccf6100939b7.tar.gz
perlweeklychallenge-club-70a6662428f2c7982de421eb63bfccf6100939b7.tar.bz2
perlweeklychallenge-club-70a6662428f2c7982de421eb63bfccf6100939b7.zip
Add solution to 042 by E. Choroba
-rwxr-xr-xchallenge-042/e-choroba/perl5/ch-1.pl6
-rwxr-xr-xchallenge-042/e-choroba/perl5/ch-2.pl24
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';