diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-10-29 23:40:36 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-29 23:40:36 +0000 |
| commit | c4a58a2c3a21cfeffe5a04cd41f89b9a23f583f7 (patch) | |
| tree | dc783a31b6bc2588be6075d932e6481423d8f849 | |
| parent | eb2ba31aaf5c79ebf0f8072b45753a21197e9a1d (diff) | |
| parent | 668bbfaa918de0dd1dcabd15812f1f89de4838fb (diff) | |
| download | perlweeklychallenge-club-c4a58a2c3a21cfeffe5a04cd41f89b9a23f583f7.tar.gz perlweeklychallenge-club-c4a58a2c3a21cfeffe5a04cd41f89b9a23f583f7.tar.bz2 perlweeklychallenge-club-c4a58a2c3a21cfeffe5a04cd41f89b9a23f583f7.zip | |
Merge pull request #8962 from augiedb/challenge-240
Challenge 240 Completed
| -rw-r--r-- | challenge-240/augiedb/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-240/augiedb/perl/ch-1.pl | 15 | ||||
| -rw-r--r-- | challenge-240/augiedb/perl/ch-2.pl | 56 |
3 files changed, 72 insertions, 0 deletions
diff --git a/challenge-240/augiedb/blog.txt b/challenge-240/augiedb/blog.txt new file mode 100644 index 0000000000..06b02443c1 --- /dev/null +++ b/challenge-240/augiedb/blog.txt @@ -0,0 +1 @@ +https://variousandsundry.com/an-attempt-to-simplify-fails-but-works/ diff --git a/challenge-240/augiedb/perl/ch-1.pl b/challenge-240/augiedb/perl/ch-1.pl new file mode 100644 index 0000000000..11820f512e --- /dev/null +++ b/challenge-240/augiedb/perl/ch-1.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl +use warnings; +use strict; + +## +## Just wanted to highlight a one-line solution to the problem. +## I'm not rigging up a main() and a series of tests. +## Trust me; it works. =) +## + +my @string = ("Perl", "Python", "Pascal"); +my $chk = "ppp"; + +print $chk eq join('', map { lc( substr($_, 0, 1) ) } @string ) ? "True" : "False"; + diff --git a/challenge-240/augiedb/perl/ch-2.pl b/challenge-240/augiedb/perl/ch-2.pl new file mode 100644 index 0000000000..a4c8b5b81e --- /dev/null +++ b/challenge-240/augiedb/perl/ch-2.pl @@ -0,0 +1,56 @@ +#!/usr/bin/perl +use strict; +use warnings; + +## +## +## The real solution to this challenge is +## one line in the build_array() subroutine. +## +## Skip head to line 32 for that. +## + +main( (0, 2, 1, 5, 3, 4) ); +main( (5, 0, 1, 2, 3, 4) ); + +sub main { + + my @int = @_; + + print "Input: "; + pretty_print_array( @int ); + print "Output: "; + pretty_print_array( build_array( @int ) ); + print "\n"; + +} + +sub build_array { + + my @int = @_; + + return map{ $int[$_] } @int; + +} + +sub pretty_print_array { + + my @array = @_; + my $length = scalar @array; + my $count = 1; + + print "("; + + foreach my $value(@array) { + print $value; + print ", " if $count < $length; + $count++; + } + + print ")\n"; + + return; +} + + + |
