aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-05-31 21:15:28 +0100
committerGitHub <noreply@github.com>2021-05-31 21:15:28 +0100
commita4fc702b53f8a565f06d8177265d23b6ee8325cb (patch)
treeed63dd455dcf31f9f19ac5d93f8073a4f6031a0c
parent77230071b93c20d1ebab12439dca03e328198814 (diff)
parent66c611541ecc6a46a880a86b7384aef3bae8745b (diff)
downloadperlweeklychallenge-club-a4fc702b53f8a565f06d8177265d23b6ee8325cb.tar.gz
perlweeklychallenge-club-a4fc702b53f8a565f06d8177265d23b6ee8325cb.tar.bz2
perlweeklychallenge-club-a4fc702b53f8a565f06d8177265d23b6ee8325cb.zip
Merge pull request #4179 from seaker/master
challenge 115, Feng Chang's raku solutions
-rwxr-xr-xchallenge-115/feng-chang/raku/ch-1.raku12
-rwxr-xr-xchallenge-115/feng-chang/raku/ch-2.raku23
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-115/feng-chang/raku/ch-1.raku b/challenge-115/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..0634f261fc
--- /dev/null
+++ b/challenge-115/feng-chang/raku/ch-1.raku
@@ -0,0 +1,12 @@
+#!/bin/env raku
+
+sub MAIN(*@S) {
+ for @S.permutations -> @s {
+ if (^@s.elems).map({ @s[$_].substr(*-1) eq @s[($_+1) % @s.elems].substr(0,1) }).all {
+ put 1;
+ exit;
+ }
+ }
+
+ put 0;
+}
diff --git a/challenge-115/feng-chang/raku/ch-2.raku b/challenge-115/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..228ab113ea
--- /dev/null
+++ b/challenge-115/feng-chang/raku/ch-2.raku
@@ -0,0 +1,23 @@
+#!/bin/env raku
+
+sub largest-even(UInt:D $n --> UInt:D) {
+ my @d = $n.combĀ».UInt; # get all digits
+ my $last-digit = @d.grep(* %% 2).min; # find the smallest even digit
+
+ my Bool $done = False;
+ @d .= grep({ $done or $_ != $last-digit ?? True !! do { $done = True; False }}); # filter out the found even digit, only once
+
+ (@d.sort({ $^b <=> $^a }).join ~ $last-digit).UInt # 'print' the array, largest to smallest, at last, 'print' the found even digit
+}
+
+multi MAIN('test') {
+ use Test;
+
+ is largest-even(1026), 6210, '1,0,2,6 -> 6210';
+ is largest-even(1428), 8412, '1,4,2,8 -> 8412';
+ is largest-even(4176), 7614, '4,1,7,6 -> 7614';
+
+ done-testing;
+}
+
+multi MAIN(UInt:D $n) { put largest-even($n) }