diff options
| -rw-r--r-- | challenge-277/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-277/paulo-custodio/perl/ch-1.pl | 43 | ||||
| -rw-r--r-- | challenge-277/paulo-custodio/perl/ch-2.pl | 40 | ||||
| -rw-r--r-- | challenge-277/paulo-custodio/t/test-1.yaml | 15 | ||||
| -rw-r--r-- | challenge-277/paulo-custodio/t/test-2.yaml | 10 | ||||
| -rw-r--r-- | challenge-282/jaldhar-h-vyas/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-282/jaldhar-h-vyas/perl/ch-1.sh | 3 | ||||
| -rwxr-xr-x | challenge-282/jaldhar-h-vyas/perl/ch-2.pl | 15 | ||||
| -rwxr-xr-x | challenge-282/jaldhar-h-vyas/raku/ch-1.sh | 3 | ||||
| -rwxr-xr-x | challenge-282/jaldhar-h-vyas/raku/ch-2.raku | 18 | ||||
| -rw-r--r-- | challenge-282/wambash/raku/ch-1.raku | 19 | ||||
| -rw-r--r-- | challenge-282/wambash/raku/ch-2.raku | 19 |
12 files changed, 188 insertions, 0 deletions
diff --git a/challenge-277/paulo-custodio/Makefile b/challenge-277/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-277/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-277/paulo-custodio/perl/ch-1.pl b/challenge-277/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..d2bc267287 --- /dev/null +++ b/challenge-277/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,43 @@ +#!/usr/bin/env perl + +# Challenge 277 +# +# Task 1: Count Common +# Submitted by: Mohammad Sajid Anwar +# You are given two array of strings, @words1 and @words2. +# +# Write a script to return the count of words that appears in both arrays exactly once. +# +# Example 1 +# Input: @words1 = ("Perl", "is", "my", "friend") +# @words2 = ("Perl", "and", "Raku", "are", "friend") +# Output: 2 +# +# The words "Perl" and "friend" appear once in each array. +# Example 2 +# Input: @words1 = ("Perl", "and", "Python", "are", "very", "similar") +# @words2 = ("Python", "is", "top", "in", "guest", "languages") +# Output: 1 +# Example 3 +# Input: @words1 = ("Perl", "is", "imperative", "Lisp", "is", "functional") +# @words2 = ("Crystal", "is", "similar", "to", "Ruby") +# Output: 0 + +use Modern::Perl; + +my $words = "@ARGV"; +my @words = split /,/, $words; + +my $count = []; +for my $i (0..1) { + for my $word (split ' ', $words[$i]) { + $count->[$i]{$word}++; + } +} + +my $count_same = 0; +for my $word (split ' ', @words[0..1]) { + $count_same++ if ($count->[0]{$word}//0)==1 && ($count->[1]{$word}//0)==1; +} + +say $count_same; diff --git a/challenge-277/paulo-custodio/perl/ch-2.pl b/challenge-277/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..da33b27d94 --- /dev/null +++ b/challenge-277/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,40 @@ +#!/usr/bin/env perl + +# Challenge 277 +# +# Task 2: Strong Pair +# Submitted by: Mohammad Sajid Anwar +# You are given an array of integers, @ints. +# +# Write a script to return the count of all strong pairs in the given array. +# +# A pair of integers x and y is called strong pair if it satisfies: 0 < |x - y| < min(x, y). +# +# Example 1 +# Input: @ints = (1, 2, 3, 4, 5) +# Ouput: 4 +# +# Strong Pairs: (2, 3), (3, 4), (3, 5), (4, 5) +# Example 2 +# Input: @ints = (5, 7, 1, 7) +# Ouput: 1 +# +# Strong Pairs: (5, 7) + +use Modern::Perl; +use List::Util 'min', 'uniq'; + +my @ints = uniq @ARGV; +my $count = 0; +for my $i (0..$#ints-1) { + for my $j ($i+1..$#ints) { + $count++ if is_strong_pair($ints[$i], $ints[$j]); + } +} + +say $count; + +sub is_strong_pair { + my($a, $b) = @_; + return 0 < abs($a-$b) && abs($a-$b) < min($a,$b); +} diff --git a/challenge-277/paulo-custodio/t/test-1.yaml b/challenge-277/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..03040ce356 --- /dev/null +++ b/challenge-277/paulo-custodio/t/test-1.yaml @@ -0,0 +1,15 @@ +- setup: + cleanup: + args: Perl is my friend,Perl and Raku are friend + input: + output: 2 +- setup: + cleanup: + args: Perl and Python are very similar,Python is top in guest languages + input: + output: 1 +- setup: + cleanup: + args: Perl is imperative Lisp is functional,Crystal is similar to Ruby + input: + output: 0 diff --git a/challenge-277/paulo-custodio/t/test-2.yaml b/challenge-277/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..6b7d7a47dd --- /dev/null +++ b/challenge-277/paulo-custodio/t/test-2.yaml @@ -0,0 +1,10 @@ +- setup: + cleanup: + args: 1 2 3 4 5 + input: + output: 4 +- setup: + cleanup: + args: 5 7 1 7 + input: + output: 1 diff --git a/challenge-282/jaldhar-h-vyas/blog.txt b/challenge-282/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..ae3e7d288f --- /dev/null +++ b/challenge-282/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2024/08/perl_weekly_challenge_week_282.html diff --git a/challenge-282/jaldhar-h-vyas/perl/ch-1.sh b/challenge-282/jaldhar-h-vyas/perl/ch-1.sh new file mode 100755 index 0000000000..05c62ea24e --- /dev/null +++ b/challenge-282/jaldhar-h-vyas/perl/ch-1.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +perl -E 'shift=~/(((\d)\3\3)(\3*))/;say$1==$2?$2:"-1"' "$@" diff --git a/challenge-282/jaldhar-h-vyas/perl/ch-2.pl b/challenge-282/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..be4df96953 --- /dev/null +++ b/challenge-282/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl +use v5.38; + +my @chars = split //, lc shift; +my $current = shift @chars; +my $changes = 0; + +for my $c (@chars) { + if ($c ne $current) { + $changes++; + $current = $c; + } +} + +say $changes; diff --git a/challenge-282/jaldhar-h-vyas/raku/ch-1.sh b/challenge-282/jaldhar-h-vyas/raku/ch-1.sh new file mode 100755 index 0000000000..d4eaae56d9 --- /dev/null +++ b/challenge-282/jaldhar-h-vyas/raku/ch-1.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +raku -e '@*ARGS[0]~~/(((\d)$0$0{}:my$n=$0)($n*))/;say $0==$0[0]??$0[0].Str!!"-1"' "$@"
\ No newline at end of file diff --git a/challenge-282/jaldhar-h-vyas/raku/ch-2.raku b/challenge-282/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..d730a4486d --- /dev/null +++ b/challenge-282/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,18 @@ +#!/usr/bin/raku + +sub MAIN( + $str +) { + my @chars = $str.lc.comb; + my $current = @chars.shift; + my $changes = 0; + + for @chars -> $c { + if $c ne $current { + $changes++; + $current = $c; + } + } + + say $changes; +}
\ No newline at end of file diff --git a/challenge-282/wambash/raku/ch-1.raku b/challenge-282/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..8576ac1e50 --- /dev/null +++ b/challenge-282/wambash/raku/ch-1.raku @@ -0,0 +1,19 @@ +#!/usr/bin/env raku + +sub good-integer ($int) { + $int + andthen .comb: / (\d) $0+ / + andthen .first: *.chars == 3 +} + +multi MAIN (Bool :test($)!) { + use Test; + is good-integer(12344456), '444'; + is good-integer(1233334), Nil; + is good-integer(10020003), '000'; + done-testing; +} + +multi MAIN ($int) { + say good-integer( $int ) // -1; +} diff --git a/challenge-282/wambash/raku/ch-2.raku b/challenge-282/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..4a69d904ef --- /dev/null +++ b/challenge-282/wambash/raku/ch-2.raku @@ -0,0 +1,19 @@ +#!/usr/bin/env raku + +sub changing-keys ($str) { + $str.fc + andthen .comb: / (.) $0* / + andthen .elems - 1 +} + +multi MAIN (Bool :test($)!) { + use Test; + is changing-keys('pPeERrLl'), 3; + is changing-keys('rRr'), 0; + is changing-keys('GoO'), 1; + done-testing; +} + +multi MAIN ($str) { + say changing-keys $str +} |
