Home
Tuesday, May 30, 2017
8:39:18 AM
Users online: 0   You are here >> Home > Programming

Forums | Programming Forums search
Forum FAQ
   
  1  
generating all combinations in a sequence using loops?
Athiril 
16/8/08 12:51:31 PM
Titan

Hey I wanted to test a theory I had.

But I need to generate all combinations of numbers for a certain length

for example, 3 digit, base 10, 1000 combinations, 000-999

But I dont want to do this using 3 for loops of 0-9

As it needs to cater to other lengths, say 5 digits, 13 digits, etc.

And other bases, not just base 10.

What is the flexible way of doing this?

I just downloaded VB.NET Express 2008 for this purpose, but can switch one of the other Express studios, or Dev-C++ if necessary.

edit: ive decided i can do my testing over sequences 4 digits long, the base can be changed easily.


Edited by Athiril: 16/8/2008 02:12:41 PM

-----
North Coast NSW Photo Community Forums
http://photodan.com.au/forums/

freespace 
16/8/08 10:58:32 PM
Hero
Titan


Erm, dude, you just increment from zero up to the largest number you can have with n digits, which is n 9s. Then format it as a string with padding.

Like this:

for(i = 0; i < 10000; ++i) 
{
printf('%04d\n,i);
}


To cater for other bases just cast into the other base before printing.

Seriously, you are over-engineering it.

Cheers,
Steve

-----
By perseverance the snail reached the ark.

http://www.shuningbian.net - blog
http://anonshare.pictorii.com - share files anonymously
http://dailydiscovery.b3ta.org - learn something new
its f reespace damn it!

Athiril 
20/8/08 8:23:49 AM
Titan

Doesn't matter anyway, apparently there isn't enough computing power in the universe to calculate what I was trying to do :P

-----
North Coast NSW Photo Community Forums
http://photodan.com.au/forums/

Girvo 
20/8/08 3:53:25 PM
Immortal

Quote by Athiril
Doesn't matter anyway, apparently there isn't enough computing power in the universe to calculate what I was trying to do :P



Bugger.

:P

-----
Quote by tantryl
Psychonaut doesn't count.



Quote by The_Psychonaut
:(



robzy 
20/8/08 4:02:35 PM
Hero
Immortal


What is it that you were trying to do? Don't hold out on us! :P

Rob.

-----
&#1506;&#1501; &#1497;&#1513;&#1512;&#1488;&#1500; &#1495;&#1497;

Meeko 
20/8/08 4:43:34 PM
Titan

Factorials are a bitch, aren't they?

-----

  1  
Forums | Programming