diff options
| author | LoneWolfiNTj <Hatley.Software@gmail.com> | 2023-01-31 02:45:28 -0800 |
|---|---|---|
| committer | LoneWolfiNTj <Hatley.Software@gmail.com> | 2023-01-31 02:45:28 -0800 |
| commit | 7b67e4b46510d647bc13f02a5421b2b680815075 (patch) | |
| tree | c573d59c81cf30846b78e1b2ea747ac805c3121f | |
| parent | 7b8bbfbe1ca2c8b1215b72bd7e6ea59b11a8bf1c (diff) | |
| download | perlweeklychallenge-club-7b67e4b46510d647bc13f02a5421b2b680815075.tar.gz perlweeklychallenge-club-7b67e4b46510d647bc13f02a5421b2b680815075.tar.bz2 perlweeklychallenge-club-7b67e4b46510d647bc13f02a5421b2b680815075.zip | |
Undoing accidental changes to master.
| -rw-r--r-- | challenge-202/robbie-hatley/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-202/robbie-hatley/perl/ch-1.pl | 55 | ||||
| -rwxr-xr-x | challenge-202/robbie-hatley/perl/ch-2.pl | 111 |
3 files changed, 0 insertions, 167 deletions
diff --git a/challenge-202/robbie-hatley/blog.txt b/challenge-202/robbie-hatley/blog.txt deleted file mode 100644 index 53738017e5..0000000000 --- a/challenge-202/robbie-hatley/blog.txt +++ /dev/null @@ -1 +0,0 @@ -https://hatley-software.blogspot.com/2023/01/robbie-hatleys-perl-solutions-to-weekly_31.html
\ No newline at end of file diff --git a/challenge-202/robbie-hatley/perl/ch-1.pl b/challenge-202/robbie-hatley/perl/ch-1.pl deleted file mode 100755 index 09ee58ac28..0000000000 --- a/challenge-202/robbie-hatley/perl/ch-1.pl +++ /dev/null @@ -1,55 +0,0 @@ -#! /usr/bin/perl - -# Robbie Hatley's Perl Solutions to The Weekly Challenge #202-1 - -# DESCRIPTION OF PROBLEM: - -=pod - -Task 1: Consecutive Odds -Submitted by: Mohammad S Anwar - -You are given an array of integers. Write a script to print 1 if there -are THREE consecutive odds in the given array otherwise print 0. - -Example 1: Input: (1,5,3,6) Output: 1 -Example 2: Input: (2,6,3,5) Output: 0 -Example 3: Input: (1,2,3,4) Output: 0 -Example 4: Input: (2,3,5,7) Output: 1 - -=cut - -# IO NOTES: -# NOTE: Default input is via built-in array of arrays. -# Non-default input can be provided through @ARGV. -# If using @ARGV, arguments should be a space-separated sequence -# of integers, which will be construed as being a single array. -# -# NOTE: Output is to stdout and will be 1 if 3 consecutive odds, else 0. - -# PRELIMINARIES: -use v5.36; -$,=' '; - -# SUBROUTINES: -sub tco (@a){ - for (my $i = 0 ; $i <= $#a-2 ; ++$i){ - if ( !($a[$i+0]%2) ) {$i += 0; next;} - if ( !($a[$i+1]%2) ) {$i += 1; next;} - if ( !($a[$i+2]%2) ) {$i += 2; next;} - return 1;} - return 0;} - -# DEFAULT INPUT: -my @arrays = ([1,5,3,6],[2,6,3,5],[1,2,3,4],[2,3,5,7]); - -# NON-DEFAULT INPUT: -if (@ARGV) {@arrays = ([@ARGV]);} - -# SCRIPT BODY: -for (@arrays){ - my @array = @{$_}; - my $tco = tco(@array); - say ''; - say "array = (@array)"; - say "tco = $tco";}
\ No newline at end of file diff --git a/challenge-202/robbie-hatley/perl/ch-2.pl b/challenge-202/robbie-hatley/perl/ch-2.pl deleted file mode 100755 index 2c021accaa..0000000000 --- a/challenge-202/robbie-hatley/perl/ch-2.pl +++ /dev/null @@ -1,111 +0,0 @@ -#! /usr/bin/perl - -# Robbie Hatley's Perl Solutions to The Weekly Challenge #202-2 - -# DESCRIPTION OF PROBLEM: - -=pod - -Task 2: Widest Valley -Submitted by: E. Choroba - -Given a profile as a list of altitudes, return the leftmost widest valley. -A valley is defined as a subarray of the profile consisting of two parts: -the first part is non-increasing and the second part is non-decreasing. -Either part can be empty. - -Example 1: Input: 1, 5, 5, 2, 8 Output: 5, 5, 2, 8 -Example 2: Input: 2, 6, 8, 5 Output: 2, 6, 8 -Example 3: Input: 9, 8, 13, 13, 2, 2, 15, 17 Output: 13, 13, 2, 2, 15, 17 -Example 4: Input: 2, 1, 2, 1, 3 Output: 2, 1, 2 -Example 5: Input: 1, 3, 3, 2, 1, 2, 3, 3, 2 Output: 3, 3, 2, 1, 2, 3, 3 - -=cut - -# IO NOTES: -# -# NOTE: Input is via either built-in array of arrays, or @ARGV. -# If using @ARGV, arguments should be a space-separated sequence of -# integers, which will be interpreted as being a single array -# -# NOTE: Output will be to stdout and will be the contents of each array -# followed by the left-most widest valley within that array. - -# PRELIMINARIES: -use v5.36; -$"=", "; - -# DEFAULT INPUT: -my @arrays = -( - [1, 5, 5, 2, 8], - [2, 6, 8, 5], - [9, 8, 13, 13, 2, 2, 15, 17], - [2, 1, 2, 1, 3], - [1, 3, 3, 2, 1, 2, 3, 3, 2] -); - -# NON-DEFAULT INPUT: -if (@ARGV){@arrays=([@ARGV])} - -# SCRIPT BODY: -for (@arrays){ - my @array = @{$_}; # Current array. - my $state = 'L'; # State of valley wall: 'L'=Left, 'R'=Right. - my $width = 0; # Width of most-recent valley. - my $widbi = 0; # Beginning index of widest valley found so far. - my $widest = 0; # Width of widest valley found so-far. - my @valley = (); # Left-most widest valley found so far. - my $el = 0; # Current elevation number. - my $idx = 0; # Elevation index. - my $begin = 0; # Beginning index of current valley. - - # For each elevation change, decide what to do, based valley-wall state - # and on whether we've reached the last elevation yet: - for ( my $idx = 1 ; $idx <= $#array ; ++$idx ){ - - # If we're on the Left Wall of our current valley, check to see if we - # just transitioned to the Right Wall: - if ($state eq 'L' && $array[$idx] > $array[$idx-1]){ - $state = 'R';} - - # If we're on the Right Wall of our current valley, check to see if we - # just transitioned to a new Left Wall: - if ($state eq 'R' && $array[$idx] < $array[$idx-1]){ - # How wide was that valley we just left? - $width = $idx - $begin; - - # Was that wider than the widest valley we've seen so far? - # If so, update widest-valley information accordingly: - if ($width > $widest){ - $widbi = $begin; - $widest = $width;} - - # Our old valley ended, so now let's begin a new valley: - $begin = $idx; - - # But also include any flat or down-sloping ground to the left - # of $idx as also being part of our new valley: - while ($begin >= 0 && $array[$begin-1]>=$array[$begin]){--$begin} - - # We're now on the left wall of our new valley: - $state = 'L';} - - # If end-of-array cuts off valley, then don't wait for current valley to - # terminate by R->L transition, because that can't happen! Instead, - # calculate size of current valley now, and update "widest valley" - # information if appropriate: - if ($idx == $#array){ - $width = $idx + 1 - $begin; - if ($width > $widest){ - $widbi = $begin; - $widest = $width;}}} - - # Set @valley to a slice of @array beginning with "widest beginning index" - # "$widbi" and having width "$widest": - @valley = @array[$widbi..$widbi+$widest-1]; - - # Print results: - say ''; - say "Array of elevations = (@array)"; - say "Left-most widest valley = (@valley)"}
\ No newline at end of file |
