diff options
| -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'; |
