diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2021-06-16 23:11:52 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2021-06-16 23:15:44 +0100 |
| commit | da6ecf482d935ed945022a3792e9bbfae1f2a3a8 (patch) | |
| tree | 4a7e4e55c8cb98826e39b25a4de7af5228ed53a5 | |
| parent | d017964c3a86583b2bc4ea7fd6f3d1f1b88e4b00 (diff) | |
| download | perlweeklychallenge-club-da6ecf482d935ed945022a3792e9bbfae1f2a3a8.tar.gz perlweeklychallenge-club-da6ecf482d935ed945022a3792e9bbfae1f2a3a8.tar.bz2 perlweeklychallenge-club-da6ecf482d935ed945022a3792e9bbfae1f2a3a8.zip | |
Add Perl solution to challenge 117
| -rw-r--r-- | challenge-117/paulo-custodio/perl/ch-1.pl | 35 | ||||
| -rw-r--r-- | challenge-117/paulo-custodio/perl/ch-2.pl | 61 | ||||
| -rw-r--r-- | challenge-117/paulo-custodio/t/test-1.yaml | 25 | ||||
| -rw-r--r-- | challenge-117/paulo-custodio/t/test-2.yaml | 15 | ||||
| -rwxr-xr-x | challenge-117/paulo-custodio/test.pl | 7 |
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'; |
