From 00cf4b917c093cced6ec5e3a05a975fae65b9c76 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 5 Jun 2023 12:52:21 +0000 Subject: Challenge 220 Solutions (Raku) --- challenge-220/mark-anderson/raku/ch-1.raku | 10 ++++++++++ challenge-220/mark-anderson/raku/ch-2.raku | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 challenge-220/mark-anderson/raku/ch-1.raku create mode 100644 challenge-220/mark-anderson/raku/ch-2.raku diff --git a/challenge-220/mark-anderson/raku/ch-1.raku b/challenge-220/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..c34c232700 --- /dev/null +++ b/challenge-220/mark-anderson/raku/ch-1.raku @@ -0,0 +1,10 @@ +#!/usr/bin/env raku +use Test; + +is-deeply common-characters(), ("r",); +is-deeply common-characters(), < e l v >; + +sub common-characters +{ + sort .keys given [(&)] @^a>>.comb>>.lc +} diff --git a/challenge-220/mark-anderson/raku/ch-2.raku b/challenge-220/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..11ef39a5ef --- /dev/null +++ b/challenge-220/mark-anderson/raku/ch-2.raku @@ -0,0 +1,27 @@ +#!/usr/bin/env raku +use Test; + +is-deeply squareful(1, 17, 8), ((1, 8, 17), (17, 8, 1)); +is-deeply squareful(2, 2, 2), ((2, 2, 2),); + +sub squareful(+@a) +{ + gather for @a.permutations.unique(with => &[eqv]) + { + .take if all(.rotor(2 => -1)).sum.sqrt.narrow ~~ UInt + } +} + +=begin alternate +sub squareful(+@a) +{ + my $s = @a.sort.tail(2).sum; + + my $squares := (0..$s Z* 0..$s).List; + + gather for @a.permutations.unique(with => &[eqv]) + { + .take if .rotor(2 => -1)>>.sum (<) $squares + } +} +=end alternate -- cgit