diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2024-08-14 16:41:56 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2024-08-14 16:41:56 +0100 |
| commit | 0ec6ed73b273b47c0b5c5eb445d8251c90876ac8 (patch) | |
| tree | febc9daea41fd9672cc4ed21accf4cc7bd134ed9 /challenge-279 | |
| parent | 0b8b99d107bb9cdf696217f1fbb5ff375b9097b6 (diff) | |
| download | perlweeklychallenge-club-0ec6ed73b273b47c0b5c5eb445d8251c90876ac8.tar.gz perlweeklychallenge-club-0ec6ed73b273b47c0b5c5eb445d8251c90876ac8.tar.bz2 perlweeklychallenge-club-0ec6ed73b273b47c0b5c5eb445d8251c90876ac8.zip | |
Add Perl solution to challenge 279
Diffstat (limited to 'challenge-279')
| -rw-r--r-- | challenge-279/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-279/paulo-custodio/perl/ch-1.pl | 37 | ||||
| -rw-r--r-- | challenge-279/paulo-custodio/perl/ch-2.pl | 37 | ||||
| -rw-r--r-- | challenge-279/paulo-custodio/t/test-1.yaml | 15 | ||||
| -rw-r--r-- | challenge-279/paulo-custodio/t/test-2.yaml | 15 |
5 files changed, 106 insertions, 0 deletions
diff --git a/challenge-279/paulo-custodio/Makefile b/challenge-279/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-279/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-279/paulo-custodio/perl/ch-1.pl b/challenge-279/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..8bd06d89d1 --- /dev/null +++ b/challenge-279/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,37 @@ +#!/usr/bin/env perl + +# Challenge 279 +# +# Task 1: Sort Letters +# Submitted by: Mohammad Sajid Anwar +# +# You are given two arrays, @letters and @weights. +# +# Write a script to sort the given array @letters based on the @weights. +# Example 1 +# +# Input: @letters = ('R', 'E', 'P', 'L') +# @weights = (3, 2, 1, 4) +# Output: PERL +# +# Example 2 +# +# Input: @letters = ('A', 'U', 'R', 'K') +# @weights = (2, 4, 1, 3) +# Output: RAKU +# +# Example 3 +# +# Input: @letters = ('O', 'H', 'Y', 'N', 'P', 'T') +# @weights = (5, 4, 2, 6, 1, 3) +# Output: PYTHON + +use Modern::Perl; + +@ARGV > 2 or die "Usage: $0 LETTTERS WEIGHTS...\n"; +my($letters, @weights) = @ARGV; +my @letters = split //, $letters; +say join('', + map {$_->[0]} + sort {$a->[1] <=> $b->[1]} + map {[$letters[$_], $weights[$_]]} 0..$#letters); diff --git a/challenge-279/paulo-custodio/perl/ch-2.pl b/challenge-279/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..3c3b9bf3e5 --- /dev/null +++ b/challenge-279/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,37 @@ +#!/usr/bin/env perl + +# Challenge 279 +# +# Task 2: Split String +# Submitted by: Mohammad Sajid Anwar +# +# You are given a string, $str. +# +# Write a script to split the given string into two containing exactly same +# number of vowels and return true if you can otherwise false. +# +# Example 1 +# +# Input: $str = "perl" +# Ouput: false +# +# Example 2 +# +# Input: $str = "book" +# Ouput: true +# +# Two possible strings "bo" and "ok" containing exactly one vowel each. +# +# Example 3 +# +# Input: $str = "good morning" +# Ouput: true +# +# Two possible strings "good " and "morning" containing two vowels each or +# "good m" and "orning" containing two vowels each. + +use Modern::Perl; + +my $str = "@ARGV"; +my $vowels = $str =~ tr/aeiouAEIOU/aeiouAEIOU/; +say $vowels % 2 == 0 ? "true" : "false"; # actual splitting is not necessary diff --git a/challenge-279/paulo-custodio/t/test-1.yaml b/challenge-279/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..4a196af484 --- /dev/null +++ b/challenge-279/paulo-custodio/t/test-1.yaml @@ -0,0 +1,15 @@ +- setup: + cleanup: + args: REPL 3 2 1 4 + input: + output: PERL +- setup: + cleanup: + args: AURK 2 4 1 3 + input: + output: RAKU +- setup: + cleanup: + args: OHYNPT 5 4 2 6 1 3 + input: + output: PYTHON diff --git a/challenge-279/paulo-custodio/t/test-2.yaml b/challenge-279/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..ce5b158c3d --- /dev/null +++ b/challenge-279/paulo-custodio/t/test-2.yaml @@ -0,0 +1,15 @@ +- setup: + cleanup: + args: perl + input: + output: false +- setup: + cleanup: + args: book + input: + output: true +- setup: + cleanup: + args: good morning + input: + output: true |
