aboutsummaryrefslogtreecommitdiff
path: root/challenge-163/deadmarshal/perl/ch-2.pl
blob: 91b19495135ee7334ae4ec008e249e9de099c7eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env perl
use strict;
use warnings;

sub summations{
  my ($arr) = @_;
  my ($i,$j);
  for($i = 0; $i < @$arr; ++$i){
    for($j = $i+1; $j < @$arr-1; ++$j){
      $arr->[$j+1] = $arr->[$j] + $arr->[$j+1];
    }
  }
  return $arr->[$j-1];
}

my @arr = (1,2,3,4,5);
my @arr2 = (1,3,5,7,9);
print summations(\@arr), "\n";
print summations(\@arr2), "\n";