#! /usr/bin/env perl6

BEGIN {
  my $c = $*PERL.compiler;
  my $v = $c.version;
  
  my $v6c = Version.new('2015.12');
  
  if $c.name.lc eq 'rakudo' and $v before $v6c {
    say "The currently installed version of Rakudo is $v.gist()";
    say 'which is from before the official release of Perl 6';
    say '';
    say "The earliest version of Rakudo this code should work on is $v6c.gist()";
    say '';
    say 'please go to http://p...content-available-to-author-only...6.org/downloads/';
    say 'or http://r...content-available-to-author-only...o.org/how-to-get-rakudo/';
  }
}

## ideone.com is currently using a version of
## Rakudo Perl 6 that is from more than a year before
## the official release of the Perl 6 spec tests
## so it will complain about the following line
use v6.c;

## This is vastly preffered to try and figure out
## a way to get this to work with such an ancient
## version of Rakudo

## Until they fix this I guess you will just have
## to deal with this code not working

## ( It is also annoying that they don't have colorized
## terminal support for the error that it produces )

use Test;

my @tests = (
  [1,2,3,4,5] => 0,
  [5,12,23,2,4,4,2,6,7] => 539,
  [-8,50,3,3,-123,4,17,99,13] => -1055.35694385, # -2982186493/2825761
  [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2] => 256,
  [1,0,1,0,1,0] => 1,
  [-9,-8,-1] => -16,
  [0,-3] => -3,
  [-99] => -99,
);

plan +@tests;

my &code = {reduce {&^b($^a,$^c)},flat @_ Z |(*+*,*-*,&[*],&[/],&[**])xx*}

for @tests -> $_ ( :key(@input), :value($expected) ) {
  is code(@input), $expected, .gist
}