view Looping.pm @ 6:5e09f7cf87f5

Perl版のソースコードを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Thu, 17 Feb 2011 15:32:22 +0900
parents
children
line wrap: on
line source

package Looping;

sub new {
  my $class = shift;
  my $self = {
    n0 => 1
  };
  bless $self, $class;
}

sub calc {
  my $self = shift;
  my $n = shift;
  my $n1 = $self->{n0} + (1 - 2*($n%2));
  $self->{n0} = $n;
  return $n1;
}

1;