diff options
| author | 2colours <ersterpleghthome@gmail.com> | 2022-03-14 23:30:32 +0100 |
|---|---|---|
| committer | Polgár Márton <polgar@astron.hu> | 2022-03-16 13:07:15 +0100 |
| commit | de5bfb1534dd84965592164003d4bc13a57beeb2 (patch) | |
| tree | 99f055017e8dc8bb4b167356aeed0ed73fd5ee95 /challenge-156/2colours | |
| parent | ca4c3754b8a3fc2b222ef48542c8b9b23bcb8815 (diff) | |
| download | perlweeklychallenge-club-de5bfb1534dd84965592164003d4bc13a57beeb2.tar.gz perlweeklychallenge-club-de5bfb1534dd84965592164003d4bc13a57beeb2.tar.bz2 perlweeklychallenge-club-de5bfb1534dd84965592164003d4bc13a57beeb2.zip | |
Solutions for #156
Diffstat (limited to 'challenge-156/2colours')
| -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}"; |
