diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-06-04 22:13:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-04 22:13:42 +0100 |
| commit | 9cb0cb6ea151d9a154eedb143e1ad173eb2a8bb6 (patch) | |
| tree | 5d99cdc1d7892154b159a6068903912d50ed1344 /challenge-219 | |
| parent | 660da15a7962c8831ffeaf4bba5ea350600ef422 (diff) | |
| parent | f8d797dd7483d469792e6c03a0b4ba00ea47e1da (diff) | |
| download | perlweeklychallenge-club-9cb0cb6ea151d9a154eedb143e1ad173eb2a8bb6.tar.gz perlweeklychallenge-club-9cb0cb6ea151d9a154eedb143e1ad173eb2a8bb6.tar.bz2 perlweeklychallenge-club-9cb0cb6ea151d9a154eedb143e1ad173eb2a8bb6.zip | |
Merge pull request #8173 from andemark/challenge-219-Raku
ch-2.raku was inelegant and incorrect!
Diffstat (limited to 'challenge-219')
| -rw-r--r-- | challenge-219/mark-anderson/raku/ch-2.raku | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/challenge-219/mark-anderson/raku/ch-2.raku b/challenge-219/mark-anderson/raku/ch-2.raku deleted file mode 100644 index c59f4dcbce..0000000000 --- a/challenge-219/mark-anderson/raku/ch-2.raku +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env raku -use Test; - -is travel-expenditure(1,5,6,7,9,15), 11; -is travel-expenditure(1,2,3,5,7,10,11,12,14,20,30,31), 20; -is travel-expenditure(1..2500), 2088; -is travel-expenditure(1..2520), 2100; -is travel-expenditure(1..2525), 2107; -is travel-expenditure(1..2528), 2109; - -# Not the most elegant solution but it's pretty fast. - -sub travel-expenditure(+@days) -{ - my $cost; - my %cost := { 1 => 2, 7 => 7, 30 => 25 } - my %min-span := { 1 => 1, 7 => 4, 30 => 23 } - - for (30,7,1) -> $n - { - loop - { - last unless @days; - my %days = @days.antipairs; - my @mm = @days.minmax.rotor($n => $n-1); - - unless @mm - { - delete-days(@days) if @days.minmax >= %min-span{$n}; - last - } - - my @ints = do ($_ (&) @days).keys for @mm; - - my %c = @ints.classify({ .elems }); - - last unless %c.max.key >= %min-span{$n}; - - delete-days(%c.max.value.head); - - sub delete-days(@a) - { - %days{@a}:delete; - @days = %days.keys>>.Int; - $cost += %cost{$n}; - } - } - } - - $cost -} |
