Guessing a number
starion
Posts: 27
I have an application (from my previous post "combining strings") that basically trys to guess a number from 0000 to 9999.
I am not a math wiz, but I am looking for suggestions as to how I might statistically guess the correct number faster. All with the BS2 math set of course.
Thoughts anyone?
I am not a math wiz, but I am looking for suggestions as to how I might statistically guess the correct number faster. All with the BS2 math set of course.
Thoughts anyone?
Comments
Maybe I'm crazy, or had too much caffeine and little sleep last night [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Every day I wake up, just the same,
waiting for something new;
Every night I have my self to blame,
for the dreams that haven't come true...
- James Taylor
Fortunately, "brute force" on a 4 digit number is relatively quick...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
Post Edited (starion) : 3/4/2007 3:34:43 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
If the COM port speed is faster than your BS2, the only way is to go with SX development (thats a can of worms)
You could always search alternating the top and bottom working towards the center.
So the samps output would start like this:
0000
9999
0001
9998
0002
9997
Or you could work from the center out. (this is what I would do)
5000 -high number
4999 -low number
5001 -high number
4998 -low number
5002 -high number
4997 -low number
etc...
And just make code that incremented the High number up, and the low number down at every step.
Using a RANDOM mode would get nuts because you will need to keep track of ALL of your previous numbers you already tried, filling up your BS2 ram, and or EEPROM quite a bit.
The phone switch itself will go up to 19200. But most installers never change the factory setting. I don't.
I think the "center out" approach makes sense. My perception of the codes I HAVE seen used in the field is that they are in the 4000-6000 range. But that's just my perception. I could be wrong.
Of course I totally forgot that probably the FIRST code I should check is the factory default code, since a percentage of installers never change it either...
It is the fastest method for searching a linear list, resulting in an average search time of O(log2N) where N is the total number of elements (in this case 9999), O stands for order of complexity and is used to compare different algorithms time of execution in an abstract manner.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
How would this be programmed? I can't vision it without using alot of variables.
Post Edited (BPM) : 11/28/2005 9:03:37 PM GMT
But, it doesn't sound like you get that kind of feedback in your application. In your application, you either hit the number and get a 'success' feedback, or you miss the number and get a 'wrong' feedback. In this case, binary search is not going to help you.
So, as others have suggested, you can use a 'I know the distribution of this number, and it's often between 4000 and 6000' strategy to help you 'guess' numbers more likely to be correct. The 'try even' or 'try odd' approach is another way of doing it.
Note that sending 10,000 4-character strings is 40,000 characters, or 400,000 bits (using 10 bits per byte, having added a start bit and a stop bit to the 8 data bits).· At 9600 bits/sec, it should take 41.67 seconds just to send the data.
I don't know where the bottle-neck is in your process.· If it took 20 minutes to find the number (worst case) then it's taking you 8.3 seconds per guess.· I would assume the bottle-neck is the time-out before the system tells you your guess was wrong -- but there's probably no way to reduce the time-out time.
Post Edited (allanlane5) : 11/28/2005 9:37:31 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 11/28/2005 10:45:51 PM GMT
I did "pad" the SERIN's with the lowest possible setting of 1, but found that sometimes that was too short and it missed data, so I found through trial and error that a number of 10 was the most rock solid. Just a minor timing issue between the time the command is sent to the switch and when it responds, it's not instant. 20 minutes is not bad at all as far as I'm concerned, considering the alternative of having to wipe the phone switch and spend a couple of hours or more reprogramming it from scratch and trying to figure out how the previous installer set it up to make it do tricks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
It is possible to create the programming structure offline and then dump it to the switch, but it still usually takes a couple of hours just to verify everything is working the way the customer is used to.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Every day I wake up, just the same,
waiting for something new;
Every night I have my self to blame,
for the dreams that haven't come true...
- James Taylor
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10