diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-04-03 11:38:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-03 11:38:14 +0100 |
| commit | af269b2c83aec2ea31fafe12311be4fcaab4201b (patch) | |
| tree | 18da8612a2f667370eb0db6c0b6a9592bc67dd0d | |
| parent | 98b7d7b7287a922c6c79d272dcfe72774ddbbfb2 (diff) | |
| parent | c7a04613a19ee25c1844f03c194bf252b2dbc25e (diff) | |
| download | perlweeklychallenge-club-af269b2c83aec2ea31fafe12311be4fcaab4201b.tar.gz perlweeklychallenge-club-af269b2c83aec2ea31fafe12311be4fcaab4201b.tar.bz2 perlweeklychallenge-club-af269b2c83aec2ea31fafe12311be4fcaab4201b.zip | |
Merge pull request #9861 from massa/challenge012
The answers to ancient puzzles
| -rw-r--r-- | challenge-012/massa/README | 1 | ||||
| -rw-r--r-- | challenge-012/massa/raku/ch-1.raku | 48 | ||||
| -rw-r--r-- | challenge-012/massa/raku/ch-2.raku | 60 |
3 files changed, 109 insertions, 0 deletions
diff --git a/challenge-012/massa/README b/challenge-012/massa/README new file mode 100644 index 0000000000..a7c2685bb7 --- /dev/null +++ b/challenge-012/massa/README @@ -0,0 +1 @@ +Solution by Massa 👽 Humberto diff --git a/challenge-012/massa/raku/ch-1.raku b/challenge-012/massa/raku/ch-1.raku new file mode 100644 index 0000000000..433e7afe08 --- /dev/null +++ b/challenge-012/massa/raku/ch-1.raku @@ -0,0 +1,48 @@ +#! /usr/bin/env raku + +# Perl Weekly Challenge +# © 2023 Shimon Bollinger. All rights reserved. +# Last modified: Mon 15 May 2023 09:17:32 PM EDT +# Version 0.0.1 + +=begin pod +=TITLE +=head2 Task 1: Euclid Number + +=SUBTITLE +=head2 Submitted by massa + +=CHALLENGE +=head2 + +The numbers formed by adding one to the products of the smallest primes are +called the Euclid Numbers (see wiki). Write a script that finds the smallest +Euclid Number that is not prime. This challenge was proposed by Laurent +Rosenfeld.. + +=head3 Result + + Output: 30031 + +=SOLUTION + +=end pod + +# always use the latest version of Raku +use v6.*; + +sub SOLUTION() { + ^∞ ==> grep &is-prime ==> produce &[*] ==> map {$_+1} ==> first {!.is-prime} +} + +multi MAIN (Bool :$test!) { + use Testo; + + my @tests = + %{ output => 30031 }, + ; + + SOLUTION().&is: .<output>, .<text> for @tests +} # end of multi MAIN (Bool :$test!) + + diff --git a/challenge-012/massa/raku/ch-2.raku b/challenge-012/massa/raku/ch-2.raku new file mode 100644 index 0000000000..8e8fc20f7a --- /dev/null +++ b/challenge-012/massa/raku/ch-2.raku @@ -0,0 +1,60 @@ +#! /usr/bin/env raku + +# Perl Weekly Challenge +# © 2023 Shimon Bollinger. All rights reserved. +# Last modified: Mon 15 May 2023 09:17:32 PM EDT +# Version 0.0.1 + +=begin pod +=TITLE +=head2 Task 1: Merge items + +=SUBTITLE +=head2 Submitted by massa + +=CHALLENGE +=head2 + +You are given two 2-D array of positive integers, $items1 and $items2 where +element is pair of (item_id, item_quantity). + +Write a script to return the merged items. + +=head3 Example 1: + + Input: «/a/b/c/d /a/b/cd /a/b/cc /a/b/c/d/e» + Output: "/a/b" + +=SOLUTION + +=end pod + +# always use the latest version of Raku +use v6.*; + +sub SOLUTION(*@paths is copy) { + my @parts = map { last unless [eq] $_[]; $_[0] }, [Z] (@paths ==> map {$*SPEC.splitdir: .IO}); + $*SPEC.catdir: @parts +} + +multi MAIN (Bool :$test!) { + use Testo; + + my @tests = + %{ input => «/a/b/c/d /a/b/cd /a/b/cc /a/b/c/d/e», + output => "/a/b" }, + %{ input => « + /etc/apt/listchanges.conf.d /etc/apt/sources.list /etc/apt/sources.list.d + /etc/apt/sources.list.dpkg-backup /etc/apt/sources.list.save + /etc/apt/sources.list~ /etc/apt/apt.conf.d/20listchanges + /etc/apt/sources.list.d/google-chrome.list + /etc/apt/sources.list.d/google-chrome.list.save + /etc/apt/sources.list.d/nala-sources.list /etc/apt/sources.list.d/nala.list + /etc/apt/sources.list.d/steam.list.save », + output => "/etc/apt" }, + ; + + SOLUTION(|.<input>).&is: .<output>, .<text> for @tests +} # end of multi MAIN (Bool :$test!) + + |
