Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
I am working on a project for a room dictionary build wizard. What I would like to do is ask the user for the number of rooms to create, and a sample of the first 3 room numbers or the first and last room number. The algorithm would then determine all the room number in the pattern.

For example, the user may request to build 50 rooms, with the first 3 room numbers being A100, A101, A102. The algorithm would then build the list of rooms A100 - A150.

This would be simple if the room numbering pattern is always known, but in this case, the pattern would only be known by what the user enters. The next series of rooms may be B-100 through B-120, or 201B through 250B. Does anyone have any hints on how this problem might be approached?

Thank you in advance for your help!
Bradley
Posted
Comments
BillWoodruff 30-Jan-16 5:43am    
Well, yes, I have several ideas how you might do this, but, first, how about you describe in more detail what your goal is.

1. is this WinForms ? ... or ?

2. you use the word "Dictionary," what does that mean here ?

3. what have you tried so far ? show some code.

4. is it ever the case that you will want the characters to "increment: rather than (or in addition to) the numeric component. for example, would you ever want a1, b1 ... z1 ... aa1, ab1 ... az1 ... aaa1 ... ?

I'd probably make a "mask" that contains the room number format with the room number replaced by some token, that will give you the starting room number too. Then you just loop for all rooms from desired start to desired end and replace the token in the mask with the number.
 
Share this answer
 
Comments
BillWoodruff 30-Jan-16 8:06am    
Give a brief code example of the "mask," and you get my #5 :)
F-ES Sitecore 1-Feb-16 4:10am    
The mask would just be "A###" for "A100" etc, "B-###" for B-120, "###B" for "201B" and so on, with the numbers replaced for some token string. You then just count from 100-whatever and replace the ### with the current number,
Hey Bradley,

I think, Gautham Prabhu K is right, there is no standard algorithm that solves your problem out of the box. But I don't think, this is impossible either. I would split this problem into 2 steps and then solve them in inverse order:

1. Understand the pattern
2. Build the room numbers

Solution for step 2 can be rather simple. For the series A100..A149 this could look like this:

C#
const string pattern = "A{0}";
Collection<string> result = new Collection<string>();
for(int i = min; i < max; i++)
{
    result.Add(string.Format(pattern, i);
}


For other patterns, you modify the pattern string. For more complex series (use only even numbers, increment letters, anything else) you have to adapt the string.Format calls. Not to complex instill now.

Solving step 1 is not that easy. Your program must read some user input and "understand" the intended pattern. Possible approaches:

1. As F-ES Sitecore suggested, one possibility is to make the user input explicit: A form where you can mark some input as constant and some as variable would be one example. Entering a format string or a reg-ex would be two others.

2. Or you write a program that Collect some example values and tries to understand them. I pick one of your examples: "B-100" and "B-120". For sure, "B-1" can be recognized as constant and "00"/"20" as variable. It can be some effort to extend this algorithm to more possible examples, but it is possible.

In the end, one criteria is, how much time you want to invest to solve this problem.

Hope this helps,

- KM
 
Share this answer
 
Comments
Bradley S. Powers 29-Jan-16 13:01pm    
Yes, I had determined this breakdown of the solution. Generating the room numbers once the pattern is known is the easier part. Determining the pattern is more difficult. Typically room numbers will have a constant alpha component and the variable numeric component, so it may be as simple as splitting the room number into its alpha and numeric components. Thank you for your thoughts!
There is no standard algorithm for this kind of problem.
But you can split the number and alphabet part and try incrementing the unicode values for alphabet and increment the number like regular integer.
But you may need check all boundary conditions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900