if there is an integer say 111 then there are 4 ways in which it can be said:
1. one one one
2. double two one
3. one double two
4. triple one
so how can one generate all possible ways for any integer eg. 33356777 etc.
I think this can be done by automata but can’t figure out how programatically
Thanks.
The number of ways to “say”
d^nwheredis the digit andnis the number of repeats is simply2^(n-1).Why? For each place between the repeating digit at place i and place (i+1): You can either “stop there” and tell the generated number so far, and advance to the next – or you can keep counting the d’s and go on. You repeat it for each i.
To sum it all up, you go through your number, and multiply all of these: for exampe
33356777will be2^2 * 2^0 * 2^0 * 2^2 = 16