On Thu, Sep 26, 2002 at 10:32:25AM +0200, Janek Schleicher wrote:
> Jeff Aa wrote at Thu, 26 Sep 2002 10:52:46 +0200:
> 
> > I need to determine the highest common factor for a series of integers.
> > I have scribed an initial stab included below - does anyone have a
> > better HCF implementation, or any improvements to suggest?
> 
> Well, here's a funny way:
> 
> use Quantum::Superpositions;
> use List::Util qw/max/;

Surely max is:

sub max { eigenstates(any(@_) >= all(@_)) }

> sub factors {
>                  my ($n) = @_;
>                  my $q = $n / any(1..$n);
>                  return any eigenstates($q == any(1 .. $n));
> }
> 
> sub gcf {
>    max eigenstates(all(factors(shift),factors(shift))), "\n";
> }
> 
> print gcf(@ARGV);

This will unlimited input:

sub gcf { max eigenstates(all(map factors($_), @_)) }

print gcf(@ARGV), "\n";

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to