DEV Community

Discussion on: Coding Puzzles: Week of 4/8

Collapse
 
choroba profile image
E. Choroba
#!/usr/bin/perl
use warnings;
use strict;

sub perimeters {
    my ($n) = @_;
    my @f = (1, 1);
    my $s = 0;
    for (0 .. $n) {
        $s += $f[0];
        @f = ($f[1], $f[0] + $f[1]);
    }
    return 4 * $s
}

# In a good TDD tradition, I started with these lines:
use Test::More tests => 2;
is perimeters(5), 80;
is perimeters(7), 216;