aboutsummaryrefslogtreecommitdiff
path: root/challenge-042
diff options
context:
space:
mode:
authorKivanc Yazan <kyzn@cpan.org>2020-01-05 19:50:45 -0800
committerKivanc Yazan <kyzn@cpan.org>2020-01-05 19:50:50 -0800
commit02cf68f699fd591b6102e92c1885a112997fbb47 (patch)
tree7881b71f7f0354edd0c547caa3a1abdeb5d9161a /challenge-042
parent895359996318bf38dd21c0461557e13cc13e4562 (diff)
downloadperlweeklychallenge-club-02cf68f699fd591b6102e92c1885a112997fbb47.tar.gz
perlweeklychallenge-club-02cf68f699fd591b6102e92c1885a112997fbb47.tar.bz2
perlweeklychallenge-club-02cf68f699fd591b6102e92c1885a112997fbb47.zip
Kivanc Solutions for w042
Diffstat (limited to 'challenge-042')
-rwxr-xr-xchallenge-042/kivanc-yazan/perl5/ch-1.pl8
-rwxr-xr-xchallenge-042/kivanc-yazan/perl5/ch-2.pl27
-rwxr-xr-xchallenge-042/kivanc-yazan/python3/ch-1.py5
-rwxr-xr-xchallenge-042/kivanc-yazan/python3/ch-2.py23
4 files changed, 63 insertions, 0 deletions
diff --git a/challenge-042/kivanc-yazan/perl5/ch-1.pl b/challenge-042/kivanc-yazan/perl5/ch-1.pl
new file mode 100755
index 0000000000..18923e53e8
--- /dev/null
+++ b/challenge-042/kivanc-yazan/perl5/ch-1.pl
@@ -0,0 +1,8 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+# Write a script to print decimal number 0 to 50 in Octal Number System.
+for my $i (0..50){
+ printf "Decimal %d = Octal %o\n", $i, $i;
+}
diff --git a/challenge-042/kivanc-yazan/perl5/ch-2.pl b/challenge-042/kivanc-yazan/perl5/ch-2.pl
new file mode 100755
index 0000000000..ddd8376f0e
--- /dev/null
+++ b/challenge-042/kivanc-yazan/perl5/ch-2.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use List::Util qw/shuffle/;
+
+# Write a script to generate a string with random number of ( and ) brackets.
+# Then make the script validate the string if it has balanced brackets.
+
+# Let's make sure we have equal number of ( and ) to increase chances
+my $count = rand(10)+1; # Could be as low as 1, as high as 10
+my @chars = ( '(', ')' ) x $count;
+@chars = shuffle(@chars);
+print join('',@chars)."\n";
+
+# Walk through to validate
+my $current_open = 0;
+for my $char (@chars){
+ if ($char eq '('){
+ $current_open++;
+ } elsif ($current_open == 0){
+ print "Not Valid\n";
+ exit;
+ } else {
+ $current_open--;
+ }
+}
+print "Valid\n";
diff --git a/challenge-042/kivanc-yazan/python3/ch-1.py b/challenge-042/kivanc-yazan/python3/ch-1.py
new file mode 100755
index 0000000000..1068782617
--- /dev/null
+++ b/challenge-042/kivanc-yazan/python3/ch-1.py
@@ -0,0 +1,5 @@
+#!/usr/bin/env python3
+
+# Write a script to print decimal number 0 to 50 in Octal Number System.
+for i in range(51):
+ print('Decimal', i, '= Octal', oct(i))
diff --git a/challenge-042/kivanc-yazan/python3/ch-2.py b/challenge-042/kivanc-yazan/python3/ch-2.py
new file mode 100755
index 0000000000..8dd3c0169f
--- /dev/null
+++ b/challenge-042/kivanc-yazan/python3/ch-2.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+import random
+
+# Write a script to generate a string with random number of ( and ) brackets.
+# Then make the script validate the string if it has balanced brackets.
+
+# Let's make sure we have equal number of ( and ) to increase chances
+count = random.randint(1,10) # Could be as low as 1, as high as 10
+chars = [ '(', ')' ] * count
+random.shuffle(chars)
+print(''.join(chars))
+
+# Walk through to validate
+current_open = 0
+for char in chars:
+ if char == '(':
+ current_open += 1
+ elif current_open == 0:
+ print('Not Valid')
+ exit()
+ else:
+ current_open -= 1
+print('Valid')