in reply to Re: Getting combinations from a number's digits
in thread Getting combinations from a number's digits

I'll try again: I,m accepting a 3 digit number from a form.

That number has 6 possible 3-digit combinations. I have to know what those 6 3-digit combinations are so that I can take each one and check to see if it's in a MySql data base table and, if so, tell the user what dates each of the 6 combinations appeared.

It's a lottery table look-up.

Does this help? We cuurently work in a MicroFocus Cobol environment which allows us to index each digit and manipulate them.

  • Comment on Re^2: Getting combinations from a number's digits

Replies are listed 'Best First'.
Re^3: Getting combinations from a number's digits
by GrandFather (Saint) on Jul 10, 2006 at 01:13 UTC

    Ok, that's a better question. Still no code, but maybe this will get you started:

    use warnings; use strict; use Algorithm::Loops qw(NextPermute); my $number = '123'; my @digits = split //, $number; my @array = ($number); # Add the first permutation push @array, join '', @digits while NextPermute (@digits); print "@array";

    Prints:

    123 132 213 231 312 321

    DWIM is Perl's answer to Gödel
Re^3: Getting combinations from a number's digits
by Eimi Metamorphoumai (Deacon) on Jul 10, 2006 at 16:05 UTC
    If you have access to change the database, I wonder whether it would be better to store all the numbers sorted (either in the main table, or in a separate table), and then look them up that way. So if the user enters "312", you'd check for "123". Then you're only doing one lookup instead of 6.