From 6feeaa5f2efa5e3a0e27aa9610f0f686ea7c34a8 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Tue, 26 Oct 2021 15:20:25 +0800 Subject: challenge 136, raku solutions --- challenge-136/feng-chang/raku/ch-1.raku | 9 +++++++++ challenge-136/feng-chang/raku/ch-2.raku | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100755 challenge-136/feng-chang/raku/ch-1.raku create mode 100755 challenge-136/feng-chang/raku/ch-2.raku diff --git a/challenge-136/feng-chang/raku/ch-1.raku b/challenge-136/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..c1cc9c1c7e --- /dev/null +++ b/challenge-136/feng-chang/raku/ch-1.raku @@ -0,0 +1,9 @@ +#!/bin/env raku + +multi sub is-two-friendly(0) { True } +multi sub is-two-friendly(2) { True } +multi sub is-two-friendly(UInt:D \n) { n %% 2 and is-two-friendly(n div 2) } + +sub MAIN(UInt:D \m, UInt:D \n) { + put +is-two-friendly(m gcd n); +} diff --git a/challenge-136/feng-chang/raku/ch-2.raku b/challenge-136/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..418370329a --- /dev/null +++ b/challenge-136/feng-chang/raku/ch-2.raku @@ -0,0 +1,11 @@ +#!/bin/env raku + +my @fibo = 1, 2, * + * ... *; + +sub fibo-floor(UInt:D \n --> UInt:D) { + (^n).grep({ @fibo[$_] ≤ n }).max +} + +sub MAIN(UInt:D \n) { + put @fibo[0 .. fibo-floor(n)].combinations.grep(*.sum == n).elems; +} -- cgit