The Magic Café
Username:
Password:
[ Lost Password ]
  [ Forgot Username ]
The Magic Cafe Forum Index » » Magical equations » » Programme for numbers combination (0 Likes) Printer Friendly Version

magicodine
View Profile
Regular user
italy
198 Posts

Profile of magicodine
Hello there. is there a pc Programme that tells you all the possible number combinations if you tell which numbers to use?
WilburrUK
View Profile
Veteran user
389 Posts

Profile of WilburrUK
Hi,

I'm not too sure what you're asking for here.

Are you wanting to give the program some set of numbers, say (1,2,4), and If so, what "combinations" do you want it to tell you ?

There are several ways to "combine" numbers (by adding, multiplying etc), what exactly are you after?
magicodine
View Profile
Regular user
italy
198 Posts

Profile of magicodine
I'm sorry, maybe I used the wrong words. I meant that if I give for istance the numbers 1, 5 and 8 possible combinations are: 158, 851, 518, 581. 815...
I need to know with 5 numbers.
rgranville
View Profile
Elite user
Boston area
462 Posts

Profile of rgranville
If all five numbers are different, there are 120 possible combinations. We math geeks call these permutations. If you have n objects (numbers, sponge balls, whatever), you can arrange them in n! different orders, where "n!" is pronounced "n factorial," and means n x (n - 1) x (n - 2) x ... x 2 x 1. Since you have five numbers, 5! = 5 x 4 x 3 x 2 x 1 = 120.

That is assuming the five numbers are all DIFFERENT, such as 1,2,3,4,5. If you have repeats, the formula changes. If you have 1,1,1,1,1 there is only ONE permutation.

Do you need to know how many possible permutations (combinations) there are (which I just told you), or do you actually need a list of all 120 possibilities. If you need the latter, send me a PM and I'll get you going.

:banana:
WilburrUK
View Profile
Veteran user
389 Posts

Profile of WilburrUK
Also, just to add to what rgranville said, if you have a group of n digits, with m repeats of a particular digit, the number of permutation is n!/m! , if in addition to the m repeats of one digit, you have p repeats of a diffent digit, you again divide this total by p!

so, (for example) the digits 1,1,1,2,2,3,4,5 can be permuted in

8!/(3! x 2!) = 40320/(6 x 2) = 3360 ways.

And just so you know, a combination (in maths) is the same as a permutation, except that the order doesn't matter, the distinction is more relevant when picking only a sub-set of things from a larger group.

As for whether there's a program to produde these, a quick google search yielded this :
http://www.delphiforfun.org/programs/permutes_1.htm

but I haven't tried it out, so can't vouch for it.
sruli
View Profile
New user
70 Posts

Profile of sruli
Here's a Perl program to do this:
http://www.rocketaware.com/perl/perlfaq4......of_a.htm

I tried it on a box here and got this:
[root ~]# perl t.pl (<----this invokes the program)
1 2 3 (<----this is what I input)
3 2 1 (<----from here until the end is output)
2 3 1
3 1 2
1 3 2
2 1 3
1 2 3
magicodine
View Profile
Regular user
italy
198 Posts

Profile of magicodine
Thank you guys! you have been a great help, problem solved :-D
Enzo
View Profile
Loyal user
CA
248 Posts

Profile of Enzo
I'm maybe little late at this, but I've got a java script that does about the same thing. It doesn't take out doubles, but the advantage is you don't need perl to execute it. Just copy the code below into a text file (e.g. with Notepad), name it "whatever.htm" and double click on it.

Quote:
<html>
<head>
<script type="text/javascript" language='JavaScript'>
function sortNumber(a,b)
{
return a - b;
}

function combinate()
{
var arr = new Array(5);
var tmp5 = new Array(5);
var tmp4 = new Array(4);
var tmp3 = new Array(3);
var tmp2 = new Array(2);
arr[0] = document.formCombinate.n1.value;
arr[1] = document.formCombinate.n2.value;
arr[2] = document.formCombinate.n3.value;
arr[3] = document.formCombinate.n4.value;
arr[4] = document.formCombinate.n5.value;

arr.sort(sortNumber);

for (p = 0; p < 5; p++) {
tmp5 = arr.slice();
n5 = tmp5[p];
tmp5.splice(p,1);
for (i = 0; I < 4; i++)
{
tmp4 = tmp5.slice();
n4 = tmp4[i];
tmp4.splice(i,1);
for (j = 0; j < 3; j++) {
tmp3 = tmp4.slice();
n3 = tmp3[j];
tmp3.splice(j,1);
for (k = 0; k < 2; k++) {
tmp2 = tmp3.slice();
n2 = tmp2[k];
tmp2.splice(k,1);
document.write(n5+n4+n3+n2+tmp2[0]);
document.write("<br />");
}
}
}
}
}
</script>
</head>
<font color="red"><b>
Combination of 5 numbers. Enter five numbers in the five boxes below.
</b></font>

<form action="" name="formCombinate">
<table summary="">
<tr>
<td width="10">
</td>
<td>
<center>
<input type="text" size="3" name="n1">
</center>
</td>
<td>
<center>
<input type="text" size="3" name="n2">
</center>
</td>
<td>
<center>
<input type="text" size="3" name="n3">
</center>
</td>
<td>
<center>
<input type="text" size="3" name="n4">
</center>
</td>
<td>
<center>
<input type="text" size="3" name="n5">
</center>
</td>
<td>
<center>
<input type="button" value="Combinate!" onclick="combinate()">
</center>

</td>
</tr>
</table>
</form>


</body>
</html>
magicodine
View Profile
Regular user
italy
198 Posts

Profile of magicodine
Enzo, that'd be great because I can actually choose the 5 numbers I want but when I click on combinate! nothing happens
Enzo
View Profile
Loyal user
CA
248 Posts

Profile of Enzo
Hmm, you're right. Somehow copying the code does not work. Try downloading the file I attached to this post. This one works for me. You need a browser that supports JavaScript. Don't forget to
enable JavaScript as well.

Good luck.

Click here to view/download attached file.
magicodine
View Profile
Regular user
italy
198 Posts

Profile of magicodine
Fantastic!!!! thank you so much!!!
The Magic Cafe Forum Index » » Magical equations » » Programme for numbers combination (0 Likes)
[ Top of Page ]
All content & postings Copyright © 2001-2021 Steve Brooks. All Rights Reserved.
This page was created in 0.14 seconds requiring 5 database queries.
The views and comments expressed on The Magic Café
are not necessarily those of The Magic Café, Steve Brooks, or Steve Brooks Magic.
> Privacy Statement <

ROTFL Billions and billions served! ROTFL