From c7a04613a19ee25c1844f03c194bf252b2dbc25e Mon Sep 17 00:00:00 2001 From: Humberto Massa Date: Tue, 2 Apr 2024 22:11:47 -0300 Subject: The answers to ancient puzzles --- challenge-012/massa/README | 1 + challenge-012/massa/raku/ch-1.raku | 48 ++++++++++++++++++++++++++++++ challenge-012/massa/raku/ch-2.raku | 60 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 challenge-012/massa/README create mode 100644 challenge-012/massa/raku/ch-1.raku create mode 100644 challenge-012/massa/raku/ch-2.raku 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: ., . 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(|.).&is: ., . for @tests +} # end of multi MAIN (Bool :$test!) + + -- cgit