perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x86-multi-thread #### #!/usr/bin/perl -w #use strict; use warnings; use Data::Dumper; use Math::Polynomial::Solve qw! poly_derivative poly_roots !; use Math::Round qw! round !; use Devel::Size qw! size total_size !; use Scalar::Util qw! weaken isweak !; use Test::Memory::Cycle; use Test::LeakTrace; my %haystack; # $rep means right endpoint of the interval [0, $rep] my $rep = int 3; foreach my $x (3 .. $rep ) { foreach my $y (2 .. $x-1 ) { foreach my $z (1 .. $y-1 ) { # expanded form of x*(x - $x)*(x - $y)*(x - $z) # coeffs are in an array $haystack{"$x, $y, $z"} = [ poly_roots( poly_derivative( 1, -$x - $y - $z, $x*$y + $x*$z + $y*$z, -$x*$y*$z, 0 ) ) ]; } } } # for each zero in @zeros, assigns a truth value to whether or not it is within 0.0001 of an integer (1=true, 0=false) sub is_approximately_an_integer { my $eps = 0.0001; while( my $x = shift ) { # need to use "round", "int" does not work! return 0 if abs( $x-round($x) ) > $eps; } return 1 } # this returns only the arrays but loses keys #print "\nSelected arrays\n"; my @wants = grep { is_approximately_an_integer( @$_ ) } values %haystack; #print Dumper( @wants ); # this returns the keys #print "\nSelected keys...\n"; @wants = grep { is_approximately_an_integer( @{$haystack{$_}} ) } keys %haystack; print Dumper( @wants ); # and you can get the arrays as well #print "\n...and the associated array.\n"; #print Dumper( @haystack{@wants} ); my $polys = $#wants + 1; # prints out the corresponding values from %haystack #if ( @wants ) { # print "\nWe found $polys polynomials!\n"; #} else { # print "No polynomials here. Try another interval.\n"; #}; my $size = size(\%haystack); my $total_size = total_size(\%haystack); print "\nThe size of haystack is $size bytes.\n"; print "The size of haystack including references is $total_size bytes.\n"; my $sizewants = size(\@wants); my $totalsizewants = total_size(\@wants); print "\nThe size of wants is $sizewants bytes.\n"; print "The size of wants including references is $totalsizewants bytes.\n";