From ff7c27abf24d3ad05b63a0e05306b565bfccfe7f Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 7 Jan 2020 18:26:08 +0000 Subject: - Added solutions by E. Choroba. --- challenge-042/e-choroba/perl/ch-1.pl | 6 ++++++ challenge-042/e-choroba/perl/ch-2.pl | 24 ++++++++++++++++++++++++ challenge-042/e-choroba/perl5/ch-1.pl | 6 ------ challenge-042/e-choroba/perl5/ch-2.pl | 24 ------------------------ 4 files changed, 30 insertions(+), 30 deletions(-) create mode 100755 challenge-042/e-choroba/perl/ch-1.pl create mode 100755 challenge-042/e-choroba/perl/ch-2.pl delete mode 100755 challenge-042/e-choroba/perl5/ch-1.pl delete mode 100755 challenge-042/e-choroba/perl5/ch-2.pl (limited to 'challenge-042') diff --git a/challenge-042/e-choroba/perl/ch-1.pl b/challenge-042/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..d7c8ce7340 --- /dev/null +++ b/challenge-042/e-choroba/perl/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/perl/ch-2.pl b/challenge-042/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..9ab8cd3680 --- /dev/null +++ b/challenge-042/e-choroba/perl/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'; diff --git a/challenge-042/e-choroba/perl5/ch-1.pl b/challenge-042/e-choroba/perl5/ch-1.pl deleted file mode 100755 index d7c8ce7340..0000000000 --- a/challenge-042/e-choroba/perl5/ch-1.pl +++ /dev/null @@ -1,6 +0,0 @@ -#!/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 deleted file mode 100755 index 9ab8cd3680..0000000000 --- a/challenge-042/e-choroba/perl5/ch-2.pl +++ /dev/null @@ -1,24 +0,0 @@ -#!/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