From 70a6662428f2c7982de421eb63bfccf6100939b7 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Tue, 7 Jan 2020 18:49:30 +0100 Subject: Add solution to 042 by E. Choroba --- challenge-042/e-choroba/perl5/ch-1.pl | 6 ++++++ challenge-042/e-choroba/perl5/ch-2.pl | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100755 challenge-042/e-choroba/perl5/ch-1.pl create mode 100755 challenge-042/e-choroba/perl5/ch-2.pl (limited to 'challenge-042') 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'; -- cgit