My teacher gave us this problem in a lab and I need help with it. Basically, he wants us to write an algorithm to count symbols. The user will provide anywhere between 3-10 symbols and then an initial number. For example:

user:  01234567, initial number: 106
output: 107, 110, 111, 112, 113, 114, 115, 116, 117, 120, 121.

user:  abc, initial number:  bb

output:  bc, ca, cb, cc, aa, ab, ac, etc.

now after wracking my brain for the past 24 hours, i have thought to put the characters in a string, then have the initial number in another string. Then use a for loop, if statements to compare. for example:

char symbol[10];

char initial[5];

for(int i = 0; i <5; i++)
{if  (initial [5] =='\0')
if (initial [4] =='\0')
if (initial [3] =='\0')
if (initial [2] =='\0')
if (initial [1] =='\0')
for(int s=0;s<
{while( initial==symbol)
{if (symbol[i+1];

I am lost!!!! Am I on the correct path?

Edited by happygeek: fixed formatting

9 Years
Discussion Span
Last Post by Narue

Okay, let me see if I understand your problem. You're basically writing an odometer where the characters on each wheel are specified by the first input string and the both the number of wheels and starting combination are specified by the second input. Then you need to print the combinations in sequence until it reaches the starting combination again?


yes, that is correct. The main example he gave us was our numerical system. example - 0123456789. initial number 10. 11,12,13,14,15,16,17,18,19,20,21, etc.


Okay, here's my initial solution to the problem. It can be done better, but this is pretty simple and functional.

Don't change the characters themselves, change an index into the string of specified characters. When the index reaches the length of the string, reset it to 0. This creates a single wheel of an odometer:

values: "1234";
index: 1

Print values[1], index = 2
Print values[2], index = 3
Print values[3], index = 0
Print values[0], index = 1
Print values[1], index = 2

If you maintain an array of indices, you can handle multiple wheels. However, you need to consider things like 244 for the above example using three wheels. Both 4's need to flip to 0 and the 2 needs to increment.

Hint: Go from back to front and when the increment doesn't result in zero, break out of the loop.

This is a short problem, so if you get past say, 50 lines of code, you've probably gone in the wrong direction.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.