diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2020-05-18 08:58:15 +0200 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2020-05-18 08:58:15 +0200 |
| commit | 8516118fec77f8e5e643aa442615afc400d18e7b (patch) | |
| tree | 14997700d7f55311082cc2cee16e26c5b42ab3a1 | |
| parent | 0219c7323748ab95c885274661b68fac4ca14fd6 (diff) | |
| download | perlweeklychallenge-club-8516118fec77f8e5e643aa442615afc400d18e7b.tar.gz perlweeklychallenge-club-8516118fec77f8e5e643aa442615afc400d18e7b.tar.bz2 perlweeklychallenge-club-8516118fec77f8e5e643aa442615afc400d18e7b.zip | |
Task 1 done.
| -rw-r--r-- | challenge-061/luca-ferrari/raku/ch-1.p6 | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-061/luca-ferrari/raku/ch-1.p6 b/challenge-061/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..b71cce0b0c --- /dev/null +++ b/challenge-061/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,28 @@ +#!env raku +# +# +# Given a list of 4 or more numbers, +# write a script to find the contiguous sublist that has the maximum product. +# The length of the sublist is irrelevant; your job is to maximize the product. +# Example +# +# Input: [ 2, 5, -1, 3 ] +# +# Output: [ 2, 5 ] which gives maximum product 10. + + +sub MAIN() { + my @input = 2, 5, -1, 3; + my $current-max; + my @output; + + loop ( my $i = 0; $i < @input.elems; $i++ ){ + for $i ^..^ @input.elems { + @output = @input[ $i .. $_ ] if ( ! @output || ( [*] @input[ $i .. $_ ] ) > ( [*] @output ) ); + } + + + } + + say "Max product is { [*] @output } made by { @output.join( ' x ' ) }"; +} |
