diff options
| author | Jaldhar H. Vyas <jaldhar@braincells.com> | 2021-06-20 23:51:04 -0400 |
|---|---|---|
| committer | Jaldhar H. Vyas <jaldhar@braincells.com> | 2021-06-20 23:51:04 -0400 |
| commit | 8a0f96069eaf6f7cba762d960021a06211c5ba61 (patch) | |
| tree | de445e24470edbd76a7b1174eb4da84bd8bf46ad /challenge-117 | |
| parent | 255cff712c7fae9d2d5857255d2be789d77ea99c (diff) | |
| download | perlweeklychallenge-club-8a0f96069eaf6f7cba762d960021a06211c5ba61.tar.gz perlweeklychallenge-club-8a0f96069eaf6f7cba762d960021a06211c5ba61.tar.bz2 perlweeklychallenge-club-8a0f96069eaf6f7cba762d960021a06211c5ba61.zip | |
Challenge 117 by Jaldhar H. Vyas.
Diffstat (limited to 'challenge-117')
| -rw-r--r-- | challenge-117/jaldhar-h-vyas/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-117/jaldhar-h-vyas/missingrows.txt | 14 | ||||
| -rwxr-xr-x | challenge-117/jaldhar-h-vyas/perl/ch-1.pl | 25 | ||||
| -rwxr-xr-x | challenge-117/jaldhar-h-vyas/perl/ch-2.pl | 30 | ||||
| -rwxr-xr-x | challenge-117/jaldhar-h-vyas/raku/ch-1.raku | 19 | ||||
| -rwxr-xr-x | challenge-117/jaldhar-h-vyas/raku/ch-2.raku | 27 |
6 files changed, 116 insertions, 0 deletions
diff --git a/challenge-117/jaldhar-h-vyas/blog.txt b/challenge-117/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..c422df4e06 --- /dev/null +++ b/challenge-117/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2021/06/perl_weekly_challenge_week_117.html diff --git a/challenge-117/jaldhar-h-vyas/missingrows.txt b/challenge-117/jaldhar-h-vyas/missingrows.txt new file mode 100644 index 0000000000..43b9676ff7 --- /dev/null +++ b/challenge-117/jaldhar-h-vyas/missingrows.txt @@ -0,0 +1,14 @@ +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
\ No newline at end of file diff --git a/challenge-117/jaldhar-h-vyas/perl/ch-1.pl b/challenge-117/jaldhar-h-vyas/perl/ch-1.pl new file mode 100755 index 0000000000..abefc31a65 --- /dev/null +++ b/challenge-117/jaldhar-h-vyas/perl/ch-1.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl +use 5.020; +use warnings; +use English qw/ -no_match_vars /; + +my $filename = shift // die "Must specify a filename.\n"; + +open my $file, '<', $filename or die "$OS_ERROR\n"; +local $RS = undef; +my $contents = <$file>; +close $file; + +my @lines = + sort { $a <=> $b } + map { / ^ (\d+) /x; int ${^CAPTURE}[0]; } + split /\n/, $contents; + +my $counter = 1; +for my $line (@lines) { + if ($counter != $line) { + say $counter; + last; + } + $counter++; +} diff --git a/challenge-117/jaldhar-h-vyas/perl/ch-2.pl b/challenge-117/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..287bfaaad5 --- /dev/null +++ b/challenge-117/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl +use 5.020; +use warnings; + +sub makePath { + my ($currRow, $currCol, $endRow, $endCol, $path) = @_; + + if ($currRow == $endRow && $currCol == $endCol) { + say $path; + return; + } + + # go left + if ($currRow < $endRow) { + makePath($currRow + 1, $currCol, $endRow, $endCol, $path . 'L'); + } + + # go horizontal + if ($currCol < $currRow) { + makePath($currRow, $currCol + 1, $endRow, $endCol, $path . 'H'); + } + + # go right + if ($currRow < $endRow && $currCol < $endCol) { + makePath($currRow + 1, $currCol + 1, $endRow, $endCol, $path . 'R'); + } +} + +my $N = shift // die "Must specify a positive integer.\n"; +makePath(0, 0, $N, $N, q{}); diff --git a/challenge-117/jaldhar-h-vyas/raku/ch-1.raku b/challenge-117/jaldhar-h-vyas/raku/ch-1.raku new file mode 100755 index 0000000000..bb9fb31548 --- /dev/null +++ b/challenge-117/jaldhar-h-vyas/raku/ch-1.raku @@ -0,0 +1,19 @@ +#!/usr/bin/raku + +sub MAIN( + Str $filename +) { + my @lines = $filename.IO.lines.map({ + / ^ (\d+) /; + $/[0].Int; + }).sort; + + my $counter = 1; + for @lines -> $line { + if $line != $counter { + say $counter; + last; + } + $counter++; + } +}
\ No newline at end of file diff --git a/challenge-117/jaldhar-h-vyas/raku/ch-2.raku b/challenge-117/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..e52717240b --- /dev/null +++ b/challenge-117/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,27 @@ +#!/usr/bin/raku + +sub makePath($currRow, $currCol, $endRow, $endCol, $path) { + if $currRow == $endRow && $currCol == $endCol { + say $path; + return; + } + + # go left + if ($currRow < $endRow) { + makePath($currRow + 1, $currCol, $endRow, $endCol, $path ~ 'L'); + } + + # go horizontal + if ($currCol < $currRow) { + makePath($currRow, $currCol + 1, $endRow, $endCol, $path ~ 'H'); + } + + # go right + if $currRow < $endRow && $currCol < $endCol { + makePath($currRow + 1, $currCol + 1, $endRow, $endCol, $path ~ 'R'); + } +} + +sub MAIN(Int $N) { + makePath(0, 0, $N, $N, q{}); +}
\ No newline at end of file |
