diff options
| -rwxr-xr-x | challenge-156/2colours/raku/ch-1.raku | 4 | ||||
| -rwxr-xr-x | challenge-156/2colours/raku/ch-2.raku | 15 |
2 files changed, 19 insertions, 0 deletions
diff --git a/challenge-156/2colours/raku/ch-1.raku b/challenge-156/2colours/raku/ch-1.raku new file mode 100755 index 0000000000..c132c1ab02 --- /dev/null +++ b/challenge-156/2colours/raku/ch-1.raku @@ -0,0 +1,4 @@ +#!/usr/bin/env raku + + +(^Inf).grep(*.base(2).comb.sum.is-prime).head(10).say;
\ No newline at end of file diff --git a/challenge-156/2colours/raku/ch-2.raku b/challenge-156/2colours/raku/ch-2.raku new file mode 100755 index 0000000000..a1d48e4f6d --- /dev/null +++ b/challenge-156/2colours/raku/ch-2.raku @@ -0,0 +1,15 @@ +#!/usr/bin/env raku + + +multi prime-factors(1) { Bag() } +multi prime-factors($n where *.is-prime) { Bag($n) } +multi prime-factors($n) { (2..sqrt $n).first: $n %% * andthen $_ (+) prime-factors($n div $_)} + +sub is-weird($n) { + when $n == 0|1 { False } + my @proper-divisors = prime-factors($n).kxxv.combinations.map(*.reduce: &[*]).unique.grep: * != $n; + @proper-divisors.combinations.map(&sum).categorize(* cmp $n) andthen .{Same, More}:exists eqv (False, True); +} + +my $n = prompt 'Input: $n = '; +say "Output: {is-weird($n).Int}"; |
