diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-09-05 15:26:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-05 15:26:16 +0100 |
| commit | ff4e4876577fe80a4462958a06a7bd69b2700144 (patch) | |
| tree | 5c78bb7639d43563f6cf3a43868e4900992a92b5 | |
| parent | 2aabfb9a8191983b504a15d0c83f918e65393f35 (diff) | |
| parent | 61249cbe53c17ee5f881800e869e26ef109b8197 (diff) | |
| download | perlweeklychallenge-club-ff4e4876577fe80a4462958a06a7bd69b2700144.tar.gz perlweeklychallenge-club-ff4e4876577fe80a4462958a06a7bd69b2700144.tar.bz2 perlweeklychallenge-club-ff4e4876577fe80a4462958a06a7bd69b2700144.zip | |
Merge pull request #6702 from PerlBoy1967/branch-for-challenge-181
w181 - Task 1 & 2
| -rwxr-xr-x | challenge-181/perlboy1967/perl/ch-1.pl | 49 | ||||
| -rwxr-xr-x | challenge-181/perlboy1967/perl/ch-2.pl | 29 | ||||
| -rw-r--r-- | challenge-181/perlboy1967/perl/temperature.txt | 10 |
3 files changed, 88 insertions, 0 deletions
diff --git a/challenge-181/perlboy1967/perl/ch-1.pl b/challenge-181/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..1f45d10714 --- /dev/null +++ b/challenge-181/perlboy1967/perl/ch-1.pl @@ -0,0 +1,49 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 181 + - https://theweeklychallenge.org/blog/perl-weekly-challenge-181/#TASK1 + +Author: Niels 'PerlBoy' van Dijke + +Task 2: You are given a paragraph. + +Write a script to order each sentence alphanumerically and print the whole paragraph. + +=cut + +use v5.16; +use warnings; + +use Data::Printer; + + +sub reorderWords ($) { + my ($s) = @_; + + my @w = grep /\S/, sort { uc$a cmp uc$b || $a cmp $b } split /[\s\.]+/, $s; + $s =~ s/([^\s\.]+)/shift@w/egsm; + + return $s; +} + +sub sentenceOrder ($) { + my ($s) = @_; + + $s =~ s/(.+?\.)/reorderWords($1)/egsm; + + return $s; +} + +my $input = q(All he could think about was how it would all end. There was +still a bit of uncertainty in the equation, but the basics +were there for anyone to see. No matter how much he tried to +see the positive, it wasn't anywhere to be seen. The end was +coming and it wasn't going to be pretty.); + +print "Input:\n$input\n\n"; + +my $output = sentenceOrder($input); + +print "Output:\n$output\n"; diff --git a/challenge-181/perlboy1967/perl/ch-2.pl b/challenge-181/perlboy1967/perl/ch-2.pl new file mode 100755 index 0000000000..5ac91ddb98 --- /dev/null +++ b/challenge-181/perlboy1967/perl/ch-2.pl @@ -0,0 +1,29 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 181 + - https://theweeklychallenge.org/blog/perl-weekly-challenge-181/#TASK2 + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Hot Day +Submitted by: Mohammad S Anwar + +You are given file with daily temperature record in random order. + +Write a script to find out days hotter than previous day. + +=cut + +use v5.16; +use warnings; + +use File::Slurp; +use List::MoreUtils qw(slide); + +sub hotDay ($) { + grep{defined}slide{$a->[1]<$b->[1]?$b->[0]:undef}sort{$a->[0]cmp$b->[0]}map{[split(/,/)]}read_file($_[0]); +} + +say join "\n", hotDay(shift // 'temperature.txt'); diff --git a/challenge-181/perlboy1967/perl/temperature.txt b/challenge-181/perlboy1967/perl/temperature.txt new file mode 100644 index 0000000000..7b251c9aec --- /dev/null +++ b/challenge-181/perlboy1967/perl/temperature.txt @@ -0,0 +1,10 @@ +2022-08-01, 20 +2022-08-09, 10 +2022-08-03, 19 +2022-08-06, 24 +2022-08-05, 22 +2022-08-10, 28 +2022-08-07, 20 +2022-08-04, 18 +2022-08-08, 21 +2022-08-02, 25 |
