#!/usr/bin/perl 

# Calculates the sum of
#   $start + ($increment * 0) +
#   $start + ($increment * 1) +
#   $start + ($increment * 2) + ...
# for $terms terms.
sub arithmetic_progression {
    my ($start, $increment, $terms) = @_;
    return $terms * ($start + ($terms - 1) * ($increment / 2));
}

# Calculates the sum of
#   $start * ($multiplier * 0) +
#   $start * ($multiplier * 1) +
#   $start * ($multiplier * 2) + ...
# for $terms terms.
sub geometric_progression {
    my ($start, $multiplier, $terms) = @_;
    return unless $multiplier < 1 and $multiplier > -1;
    return $start * (1 - $multiplier ** $terms) / (1 - $multiplier);
}

print geometric_progression(1, 0.5, 49), "\n";