demerphq,
I am guilty. I am guilty of not spending enough time reading your question to see what you were asking for before jumping to conclusions. The conclusion I jumped to is that you wanted the largest factor greater than or equal to a certain number. To that end, here is code that I believe does that.
#!/usr/bin/perl use strict; use warnings; use Math::Big::Factors 'factors_wheel'; my $next = factor(100, 25); while ( my $factor = $next->() ) { print "$factor\n"; } sub factor { my ($target, $min) = @_; my @list = factors_wheel( $target ); my $by = $#list; my (%seen, @pos, @stop, $end_pos); my ($factor, $next, $continue) = (1, 1, 1); return sub { { $factor = 1; if ( $next ) { return () if ! $by || ! $continue; $continue = 0; @pos = (0 .. $by - 2, $by - 2); @stop = @list - $by .. $#list; $end_pos = $#pos; $by--; } my $cur = $end_pos; { if ( ++$pos[ $cur ] > $stop[ $cur ] ) { $pos[ --$cur ]++; redo if $pos[ $cur ] > $stop[ $cur ]; my $new_pos = $pos[ $cur ]; @pos[ $cur .. $end_pos ] = $new_pos .. $new_pos + +$by; } } $next = $pos[0] == $stop[0] ? 1 : 0; $factor *= $_ for @list[ @pos ]; $continue = 1 if $factor >= $min; redo if $seen{$factor}++ || $factor < $min; } return $factor; } }
While I know that this isn't what you asked for, it might be of benefit to someone.

Cheers - L~R


In reply to Re^3: Best way to make sure a number is an even multiple of another? by Limbic~Region
in thread Best way to make sure a number is an even multiple of another? by demerphq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.