Quick actions

cmd+k|ctrl+k

Navigation

Languages

Challenge 64 #1

Snippet info

Language

Raku

Visibility

public

Author

fernando-correa

Created

2020-06-09T00:30:26Z

Updated

2020-06-09T00:30:26Z

multi best-path([])     { [] }
multi best-path([[$v]]) { $v }
multi best-path([@v])   { @v }
multi best-path(@v where all(@v).elems == 1) {
    @v[*; 0]
}
multi best-path(@v) {
    my @a = best-path @v[1..*];
    my @b = best-path @v.map: { .[1..*] }
    [
        @v[0; 0],
        @a.sum > @b.sum
           ?? |@b
           !! |@a
    ]
}

say best-path [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
say best-path [[7, 4, 5, 1], [5, 3, 1, 0]];
say best-path [[0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [1, 1, 0, 1, 1], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0]];
say best-path [[]];
INFO