aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-117/paulo-custodio/perl/ch-1.pl35
-rw-r--r--challenge-117/paulo-custodio/perl/ch-2.pl61
-rw-r--r--challenge-117/paulo-custodio/t/test-1.yaml25
-rw-r--r--challenge-117/paulo-custodio/t/test-2.yaml15
-rwxr-xr-xchallenge-117/paulo-custodio/test.pl7
5 files changed, 143 insertions, 0 deletions
diff --git a/challenge-117/paulo-custodio/perl/ch-1.pl b/challenge-117/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..8d2ae98cfb
--- /dev/null
+++ b/challenge-117/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+
+# Challenge 117
+#
+# TASK #1 - Missing Row
+# Submitted by: Mohammad S Anwar
+# You are given text file with rows numbered 1-15 in random order but there
+# is a catch one row in missing in the file.
+#
+# 11, Line Eleven
+# 1, Line one
+# 9, Line Nine
+# 13, Line Thirteen
+# 2, Line two
+# 6, Line Six
+# 8, Line Eight
+# 10, Line Ten
+# 7, Line Seven
+# 4, Line Four
+# 14, Line Fourteen
+# 3, Line three
+# 15, Line Fifteen
+# 5, Line Five
+# Write a script to find the missing row number.
+
+use Modern::Perl;
+my @rows;
+while (<>) {
+ chomp;
+ my($nr, $text) = split /,\s*/, $_;
+ $rows[$nr] = $text;
+}
+say join(",", (map {$_->[0]}
+ grep {!defined $_->[1]}
+ map {[$_ => $rows[$_]]} 1..15));
diff --git a/challenge-117/paulo-custodio/perl/ch-2.pl b/challenge-117/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..6baa2d50d3
--- /dev/null
+++ b/challenge-117/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,61 @@
+#!/usr/bin/env perl
+
+# Challenge 117
+#
+# TASK #2 - Find Possible Paths
+# Submitted by: E. Choroba
+# You are given size of a triangle.
+#
+# Write a script to find all possible paths from top to the bottom right
+# corner.
+#
+# In each step, we can either move horizontally to the right (H), or move
+# downwards to the left (L) or right (R).
+#
+# BONUS: Try if it can handle triangle of size 10 or 20.
+#
+# Example 1:
+# Input: $N = 2
+#
+# S
+# / \
+# / _ \
+# /\ /\
+# /__\ /__\ E
+#
+# Output: RR, LHR, LHLH, LLHH, RLH, LRH
+# Example 2:
+# Input: $N = 1
+#
+# S
+# / \
+# / _ \ E
+#
+# Output: R, LH
+
+use Modern::Perl;
+my $N = shift || 1;
+say join(', ', paths($N));
+
+sub paths {
+ my($size) = @_;
+ my @paths;
+ find_paths(\@paths, $size, '', 0, 0);
+ return @paths;
+}
+
+sub find_paths {
+ my($paths, $size, $path, $row, $col) = @_;
+ if ($row == $size && $col == $size) { # reached end
+ push @$paths, $path;
+ }
+ else {
+ if ($row < $size) {
+ find_paths($paths, $size, $path.'L', $row+1, $col);
+ find_paths($paths, $size, $path.'R', $row+1, $col+1);
+ }
+ if ($col < $row) {
+ find_paths($paths, $size, $path.'H', $row, $col+1);
+ }
+ }
+}
diff --git a/challenge-117/paulo-custodio/t/test-1.yaml b/challenge-117/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..c473de96c2
--- /dev/null
+++ b/challenge-117/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,25 @@
+- setup:
+ cleanup:
+ args:
+ input: |
+ 1, Line one
+ output: 2,3,4,5,6,7,8,9,10,11,12,13,14,15
+- setup:
+ cleanup:
+ args:
+ input: |
+ 11, Line Eleven
+ 1, Line one
+ 9, Line Nine
+ 13, Line Thirteen
+ 2, Line two
+ 6, Line Six
+ 8, Line Eight
+ 10, Line Ten
+ 7, Line Seven
+ 4, Line Four
+ 14, Line Fourteen
+ 3, Line three
+ 15, Line Fifteen
+ 5, Line Five
+ output: 12
diff --git a/challenge-117/paulo-custodio/t/test-2.yaml b/challenge-117/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..512e041cca
--- /dev/null
+++ b/challenge-117/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: 1
+ input:
+ output: LH, R
+- setup:
+ cleanup:
+ args: 2
+ input:
+ output: LLHH, LRH, LHLH, LHR, RLH, RR
+- setup:
+ cleanup:
+ args: 3
+ input:
+ output: LLLHHH, LLRHH, LLHLHH, LLHRH, LLHHLH, LLHHR, LRLHH, LRRH, LRHLH, LRHR, LHLLHH, LHLRH, LHLHLH, LHLHR, LHRLH, LHRR, RLLHH, RLRH, RLHLH, RLHR, RRLH, RRR
diff --git a/challenge-117/paulo-custodio/test.pl b/challenge-117/paulo-custodio/test.pl
new file mode 100755
index 0000000000..cf1ced98e0
--- /dev/null
+++ b/challenge-117/paulo-custodio/test.pl
@@ -0,0 +1,7 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use 5.030;
+
+require '../../challenge-001/paulo-custodio/test.pl';