diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-10 22:24:10 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-10 22:24:10 +0100 |
| commit | 3438420d6c9352f183adeb0f2835371df1866918 (patch) | |
| tree | 13d2546744de4ee58619b09e9d13f4f0ee4e4519 | |
| parent | 78112c69d929854c3a33984147a8e797141f4658 (diff) | |
| parent | 76788423763430e2ac8990eadab307093bab4b76 (diff) | |
| download | perlweeklychallenge-club-3438420d6c9352f183adeb0f2835371df1866918.tar.gz perlweeklychallenge-club-3438420d6c9352f183adeb0f2835371df1866918.tar.bz2 perlweeklychallenge-club-3438420d6c9352f183adeb0f2835371df1866918.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
| -rwxr-xr-x | challenge-172/2colours/raku/ch-1.raku | 32 | ||||
| -rw-r--r-- | challenge-172/2colours/raku/ch-2.raku | 18 |
2 files changed, 50 insertions, 0 deletions
diff --git a/challenge-172/2colours/raku/ch-1.raku b/challenge-172/2colours/raku/ch-1.raku new file mode 100755 index 0000000000..0ee9b236ff --- /dev/null +++ b/challenge-172/2colours/raku/ch-1.raku @@ -0,0 +1,32 @@ +#!/usr/bin/env raku + +constant @primes = (1 .. *).grep: &is-prime; + +multi prime-partition($sum, $count) { + gather samewith $sum, $count, 1, () +} + +#bound check (could be more accurate for sure) +sub unfinishable($sum, $count, $chosen-prime) { $sum < $count * $chosen-prime } + +#terminating when done +multi prime-partition($sum, 0, $, @rest) { + take @rest if $sum == 0; +} + +# +multi prime-partition($sum, $count, $lower-bound, @rest) { + my &finishable = { !unfinishable($sum, $count, $_) }; + my @prime-range = lazy @primes.toggle: :off, * > $lower-bound; + @prime-range .= toggle: &finishable; + samewith $sum - $_, $count - 1, $_, (|@rest, $_) for @prime-range; +} + +sub MAIN( + Int $m, + Int $n +) { + say "Input: \$m = $m, \$n = $n"; + my $output = prime-partition($m, $n).map(*.join: ', ').join: ' or '; + say "Output: $output"; +}
\ No newline at end of file diff --git a/challenge-172/2colours/raku/ch-2.raku b/challenge-172/2colours/raku/ch-2.raku new file mode 100644 index 0000000000..141a587750 --- /dev/null +++ b/challenge-172/2colours/raku/ch-2.raku @@ -0,0 +1,18 @@ +class IntSample does Associative { + has @!data; + submethod BUILD(:@data) { + @!data = sort @data; + } + method AT-KEY($scale) { + given $scale { + when Whatever { @!data[@!data - 1] } + when WhateverCode { @!data[.(@!data - 1)] } + when Int { @!data[$_] } + when * %% 0.5 { (.[$scale.floor] + .[$scale.ceiling]) / 2 given @!data } + default { @!data[.round] } + } + } + +} + +say IntSample.new(data => $*IN.lines>>.Int){0,*/4,*/2,* * 3/4, *} |
