# InferWhatever.pm 20oct08waw package InferWhatever; { # begin package closure use warnings; use strict; our $VERSION = '0.1.0'; our @EXPORT = (); our @EXPORT_OK = qw(series); use Exporter; our @ISA = qw(Exporter); sub Iterator (&) { return $_[0] } sub series { return if @_ < 2; my @s = @_; # at least 2 parameters: 1st difference(s) must exist. my @d1 = map $s[$_] - $s[$_-1], 1 .. $#s; # repeat sequence: 3, 3, ... return Iterator { return $s[-1] } if zeros(@d1); # any 2nd difference(s) (at least 3 parameters)? return unless my @d2 = map $d1[$_] - $d1[$_-1], 1 .. $#d1; # arithmetic sequence: 5, 9, 13, ... return Iterator { return $s[-1] += $d1[-1] } if zeros(@d2); # any 3rd difference(s) (at least 4 parameters)? return unless my @d3 = map $d2[$_] - $d2[$_-1], 1 .. $#d2; # quadratic sequence: 1, 4, 9, 16, ... return Iterator { $s[-1] += $d1[-1] += $d2[-1] } if zeros(@d3); return; # that's all for now ######################## # any 4th difference(s) (at least 5 parameters)? return unless my @d4 = map $d3[$_] - $d3[$_-1], 1 .. $#d3; } sub zeros { return unless @_; $_ and return for @_; return 1 } } # end package InferWhatever closure 1; # inclusion success