From 61249cbe53c17ee5f881800e869e26ef109b8197 Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Mon, 5 Sep 2022 10:47:27 +0000 Subject: w181 - Task 1 & 2 --- challenge-181/perlboy1967/perl/ch-1.pl | 49 ++++++++++++++++++++++++++ challenge-181/perlboy1967/perl/ch-2.pl | 29 +++++++++++++++ challenge-181/perlboy1967/perl/temperature.txt | 10 ++++++ 3 files changed, 88 insertions(+) create mode 100755 challenge-181/perlboy1967/perl/ch-1.pl create mode 100755 challenge-181/perlboy1967/perl/ch-2.pl create mode 100644 challenge-181/perlboy1967/perl/temperature.txt 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 -- cgit