Follow us on Twitter!
The measure of a mans life is not how well he dies, but how well he lives.
Wednesday, April 16, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 27
Guests Online: 22
Members Online: 5

Registered Members: 82811
Newest Member: IsaiahBowman
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Algorithms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 31-01-06 19:58
i cant make out the algorithm for all possible solustions for 'n' different numbers (or whatever) in a row. can anyone give me any tip (or the whole algorithm)?

example: if n=3 then:
1. 1 2 3
2. 1 3 2
3. 2 1 3
4. 2 3 1
5. 3 1 2
6. 3 2 1


Author

RE: Algorithms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 31-01-06 20:26
you want the combo's or the amount?


Author

RE: Algorithms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 31-01-06 22:12
i dont want to know how many are the possibilities (in my example=6), but an algorithm to output all those rows...




Edited by on 31-01-06 22:14
Author

RE: Algorithms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 31-01-06 22:23
Erm, I can't quiet get it to work. but, here, n=3 so two begin with each one, so if it were n=4 then you have 3 begining with each number then 2 with the same number next if you understand what i mean. and then one. so
n=5
wxyz
wxy
wx
w
if you get what i mean w, x, y, z being parts.




Edited by on 31-01-06 22:24
Author

RE: Algorithms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 02-02-06 15:14
Hi,
Have you learnt permutations and combinations in Math? well, like with 1,2,3 you can make 6 combos. with 4 you can make 24. Is that what you mean? You can find it by finding n! (n factorial). It means
1x2x3x4x.......xn.

A simple loop would be:

$fact=1;
for($i=1;$i<=$n;$i++)
$fact*=$i;

At the end of that $fact will have the factorial of n. Is that what you wanted?

ThomasB)
Author

RE: Algorithms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 02-02-06 16:28
no man this not what i want, but thanks for tring to help!
what i want is all the compinations of n continuing numbers (or letters, or whatever...). just the algorithm.


Author

RE: Algorithms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 02-02-06 17:23
thousandandone, try reading ll the posts before replying Smile


Author

RE: Algorithms

knutrainer
Member



Posts: 243
Location:
Joined: 08.07.05
Rank:
Apprentice
Posted on 02-02-06 18:17
That was thomasantony.


img389.imageshack.us/img389/974/knu5ui1ja.jpg
~PM me if you need help or instant message me.


knutrainer@gmail.com
Author

RE: Algorithms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 02-02-06 18:19
There are a few ways that you could solve this. I'd recommend using recursion to get the job done. Off the top of my head with no testing, so bear with me.

pseudo code:

Code
function generate(data,x='',n=0) {
    if (!n--) return false; //controls the end of recursion
    for each piece of data { //loop through each piece of data (1,2,3 in your example)
        foo=x.data_piece;  //create the possible solution such as 11,12,13,111,112, etc
        generate(data,foo,n); //generate the next set
    }
}

generate(array(1,2,3,4),'',7); //generate data until length=7





HTH

ps. sorry, the code parser appears to be non existant on here

Edited by on 02-02-06 18:28