From 3015f29b69459f52276877a6b34bed615a6fbb99 Mon Sep 17 00:00:00 2001 From: Augie De Blieck Jr Date: Sun, 29 Oct 2023 11:40:13 -0400 Subject: Weekly Challenge solutions for AugieDB --- challenge-240/augiedb/perl/ch-1.pl | 15 ++++++++++ challenge-240/augiedb/perl/ch-2.pl | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 challenge-240/augiedb/perl/ch-1.pl create mode 100644 challenge-240/augiedb/perl/ch-2.pl 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; +} + + + -- cgit From 668bbfaa918de0dd1dcabd15812f1f89de4838fb Mon Sep 17 00:00:00 2001 From: Augie De Blieck Jr Date: Sun, 29 Oct 2023 11:44:35 -0400 Subject: Almost forgot the blog link.... --- challenge-240/augiedb/blog.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-240/augiedb/blog.txt 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/ -- cgit