# split number (all possibilities)

• 04-13-2008
l2u
split number (all possibilities)
Hello

I need a function that will split number this way:

For instance if I have 1234:

Code:

```1 2 3 4 12 3 4 1 23 4 1 2 34 12 34 123 4 1 234 1234```
This means all possibilities how you can separate the number in '1234'..

Does anyone have similar code? I'm not sure what I should write in google to search for something like that..

Any help is highly appreciated!
• 04-13-2008
Codeplug
In your example, the relative position of each number stays the same - is this a requirement?

gg
• 04-13-2008
PING
Depends on how large your number is.. The total number of ways will be 2^(number of digits-1). Use a bitmask to represent which gap has to be left untouched. For example a binary bitmask of 010 for your number 1234 would imply something like 12 34 . The middle gap is used as there is a 1 in that position while the others are not. So loop from 0 to 2^(digits-1) and put gaps at positions where there is a 1 in the number and you will get all the required ways to split your number.
• 04-13-2008
l2u
Quote:

Originally Posted by Codeplug
In your example, the relative position of each number stays the same - is this a requirement?

gg

Yes.