From 93b3e9f803c45403f40a0dbb6018706de540e9d2 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Thu, 14 Oct 2021 03:20:28 +0100 Subject: - Updated headers as suggested by Colin. --- challenge-131/peter-campbell-smith/perl/ch-1.pl | 56 ++++++++++++------------- challenge-131/peter-campbell-smith/perl/ch-2.pl | 36 ++++++++-------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/challenge-131/peter-campbell-smith/perl/ch-1.pl b/challenge-131/peter-campbell-smith/perl/ch-1.pl index e7f902759b..17b15e8966 100755 --- a/challenge-131/peter-campbell-smith/perl/ch-1.pl +++ b/challenge-131/peter-campbell-smith/perl/ch-1.pl @@ -3,44 +3,42 @@ use strict; use warnings; use v5.10; -# PWC 131 task 2 - Peter Campbell Smith - 2021-09-20 +# PWC 131 task 1 - Peter Campbell Smith - 2021-09-20 -# You are given a string of delimiter pairs and a string to search. - -# Write a script to return two strings, the first with any characters matching -# the “opening character” set, the second with any matching the “closing character” set. +# You are given a sorted list of unique positive integers. +# Write a script to return list of arrays where the arrays are consecutive integers. my ($delimiter_pairs, $search_string, $openers, $closers); # loop over input values until (eof(DATA)) { - $delimiter_pairs = ;; - $search_string = ; - chop($delimiter_pairs, $search_string); - do_task(); + $delimiter_pairs = ;; + $search_string = ; + chop($delimiter_pairs, $search_string); + do_task(); } sub do_task { - - my ($openers, $closers, $opens, $closes); - - # copy the search string - $openers = $closers = $search_string; - - # pick off the delimiters in pairs and make strings of the opening and closing characters - while ($delimiter_pairs =~ m|(.)(.)|g) { - $opens .= $1; - $closes .= $2; - } - - # remove all but the opening characters from $openers and similarly with $closers - $openers =~ s|[^\Q$opens\E]||g; - $closers =~ s|[^\Q$closes\E]||g; - - say qq[\nDelimiter pairs: $delimiter_pairs]; - say qq[Search string: $search_string]; - say qq[Openers: $openers]; - say qq[Closers: $closers]; + + my ($openers, $closers, $opens, $closes); + + # copy the search string + $openers = $closers = $search_string; + + # pick off the delimiters in pairs and make strings of the opening and closing characters + while ($delimiter_pairs =~ m|(.)(.)|g) { + $opens .= $1; + $closes .= $2; + } + + # remove all but the opening characters from $openers and similarly with $closers + $openers =~ s|[^\Q$opens\E]||g; + $closers =~ s|[^\Q$closes\E]||g; + + say qq[\nDelimiter pairs: $delimiter_pairs]; + say qq[Search string: $search_string]; + say qq[Openers: $openers]; + say qq[Closers: $closers]; } __DATA__ diff --git a/challenge-131/peter-campbell-smith/perl/ch-2.pl b/challenge-131/peter-campbell-smith/perl/ch-2.pl index 1c364e87dc..bc22d0b343 100755 --- a/challenge-131/peter-campbell-smith/perl/ch-2.pl +++ b/challenge-131/peter-campbell-smith/perl/ch-2.pl @@ -3,32 +3,34 @@ use strict; use warnings; use v5.10; -# PWC 131 task 1 - Peter Campbell Smith - 2021-09-20 +# PWC 131 task 2 - Peter Campbell Smith - 2021-09-20 -# You are given a sorted list of unique positive integers. -# Write a script to return list of arrays where the arrays are consecutive integers. +# You are given a string of delimiter pairs and a string to search. + +# Write a script to return two strings, the first with any characters matching +# the “opening character” set, the second with any matching the “closing character” set. my $input; # loop over input examples until (eof(DATA)) { - $input = ; - chop $input; - do_task(); + $input = ; + chop $input; + do_task(); } sub do_task { - - my ($prev, $output); - - # loop over list - $prev = -1; - while ($input =~ m|(\d+)|g) { # consecutive # non-consecutive - $output .= ($1 == ($prev + 1)) ? ", $1" : "], [$1"; - $prev = $1; - } - $output =~ s|...|(|; # tidy the start of $output - say "\nInput: ($input)\nOutput: $output])"; + + my ($prev, $output); + + # loop over list + $prev = -1; + while ($input =~ m|(\d+)|g) { # consecutive # non-consecutive + $output .= ($1 == ($prev + 1)) ? ", $1" : "], [$1"; + $prev = $1; + } + $output =~ s|...|(|; # tidy the start of $output + say "\nInput: ($input)\nOutput: $output])"; } __DATA__ -- cgit