home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Here is another project then

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2473
Discussions: 200,960, Posts: 2,379,558, Members: 246,330
Old January 3rd, 2003, 12:39 AM   Digg it!   #1 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
Here is another project then

See how many tries and how long it takes you to create a random string of "techimo".

Rules:
  • All random strings must contain 7 letters
  • All random strings be able to contain any of the 26 letters of the alphabet (meaning, don't make a random num between 1 and 7 and with only t, e, c, h, i, m, o).
  • Seed your random number appropriately. No "cheating" to get a head start
  • Use whatever language you want


Once you get it debugged and working, then do 3 runs only. Average out the times and iterations it took you to get "techimo."
Post your results, and your code if you want.
Creosote is offline   Reply With Quote
Old January 3rd, 2003, 12:54 AM     #2 (permalink)
Ultimate Member
 
PyroSama's Avatar
 
Join Date: Nov 2002
Location: Boise, Idaho
Posts: 2,782
Send a message via ICQ to PyroSama Send a message via MSN to PyroSama
Why?
__________________
JOIN [FaD] | TEAM NUMBER 2037 | http://www.techimo.com/forum/t121132.html
PyroSama is offline   Reply With Quote
Old January 3rd, 2003, 12:57 AM     #3 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
Just thinkin of something to do, going along with the previous thread below this one. If you don't like it, you don't have to do it.


Edit: I gave up after 2.1 billion iterations.

Last edited by Creosote : January 3rd, 2003 at 02:41 AM.
Creosote is offline   Reply With Quote
Old January 3rd, 2003, 10:42 PM     #4 (permalink)
Banned
 
qball's Avatar
 
Join Date: Oct 2001
Posts: 447
gave up?

Let's see:

for 7 char random generated string there are:

26**7 possibilities, that's 8031810176, assuming not generating unique chars, as in "aaaaaaa" is possible.

which is 8.change billion???

just looping through 8031810176 iterations without even DOING anything will probably takes minutes on even the hardiest of hardware.

maybe we should try somehting a little more reasonable like trying "tech" first, then push the envelope to go further...

just doing 4 chars, three tries:

6.599 seconds
1010925 loops

3.215 seconds
445908 loops

2.994 seconds
418538 loops

please note:

for 4 char random generated string there are:

26**4 possibilities, that's 456976

as far as why?

I find this a little more constuctive than 'the most ridiculous way to compute 2+2. One can actually learn something...
qball is offline   Reply With Quote
Old January 4th, 2003, 04:49 AM     #5 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
thanks cueball. Actually 4 and 5 characters was nothing as far as time. 7 was in fact, taking well over an hour when I quit. I was using C# however.

But, possibly my method could have been flawed as I was not reseeding my numbers, so it could be possible that I may never generate that string for quite a while depending on what I started with.

Edit:

Here is mine with just using "tech"

403710 iterations, 0.68 seconds
272761 iterations, 0.48 seconds
495914 iterations, 0.89 seconds

Qball, are you sure your seconds figures are right?

Last edited by Creosote : January 4th, 2003 at 04:01 PM.
Creosote is offline   Reply With Quote
Old January 5th, 2003, 09:22 PM     #6 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
Hey, this is fun!

I've got it down to 6.83e-08 sec/It (14.64 MIt/s) on my Athlon XP 1700+, using gcc with -O3 -march=athlon-xp for optimizations.

The bottleneck seems to be the rand() calls, they take 4e-08 seconds but only give 31 bits; "techimo" is 7 alphas, just under 33 bits, so even if I wrote my own PRNG it would be constrained by the architecture to 32 bits (bring on the 64-bit processor!)

I tried the simple route of making 2 rand() calls per iteration:
Code:
do {
        r1 = rand() % _26_EXP_4;
        r2 = rand() % _26_EXP_3;
        ++iter;
} while ( r1 != tech || r2 != imo );
this works but takes 8.2e-08 seconds per iteration because of the two rand() calls.

so... I spread things out: each rand() call gives 31 bits = 6.60 alphas, I cut that down to 6 alphas (i.e. % _6_EXP_6) and spread 7 rand() calls over 6 iterations by combining them into a single loop:
Code:
do {
        r1 = rand() % _26_EXP_6;
        randval = rand() % _26_EXP_6;
        r2 = randval % _26;
        randval /= _26;
        ++iter;
        if ( r1 == techim && r2 == o ) break;

        r1 = randval * _26_EXP_1;
        randval = rand() % _26_EXP_6;
        r1 += randval % _26_EXP_1;
        randval /= _26_EXP_1;
        r2 = randval % _26;
        randval /= _26;
        ++iter;
        if ( r1 == techim && r2 == o ) break;
...
        r1 = randval * _26_EXP_4;
        randval = rand() % _26_EXP_6;
        r1 += randval % _26_EXP_4;
        randval /= _26_EXP_4;
        r2 = randval % _26;
        randval /= _26;
        ++iter;
        if ( r1 == techim && r2 == o ) break;

        r1 = randval * _26_EXP_5;
        randval = rand() % _26_EXP_6;
        r1 += randval % _26_EXP_5;
        randval /= _26_EXP_5;
        r2 = randval;
        ++iter;
        if ( r1 == techim && r2 == o ) break;
} while ( 1 );
this averages at 1 1/6 rand() calls and 6 1/6 arithmetic operations per iteration:
2736114671 iterations, 187.43 seconds, 14.60 MIt/s, 6.85022e-08 s/It.
3591265471 iterations, 245.30 seconds, 14.64 MIt/s, 6.83046e-08 s/It.
6688730912 iterations, 457.80 seconds, 14.61 MIt/s, 6.84435e-08 s/It.

I'm not too sure how to improve this: maybe it can be streamlined a bit or even ( ) rewritten in assembler!

Actually, this is a great problem; it's one bit too complex to manage in a single pass through a 32-bit processor, but test runs take 5-10 minutes - long enough that tweak-compile-run gets annoying but short enough that you get an answer in a reasonable timescale. Nice one creosote!
strangerstill is offline   Reply With Quote
Old January 5th, 2003, 09:38 PM     #7 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
Cool. I'm gonna have to try that now, using the 2 random numbers. Stay tuned!
Creosote is offline   Reply With Quote
Old January 6th, 2003, 03:39 AM     #8 (permalink)
Senior Member
 
Join Date: Oct 2001
Posts: 881
Send a message via AIM to zskillz
soo.... what language is that stranger??

-Z
zskillz is offline   Reply With Quote
Old January 6th, 2003, 07:54 AM     #9 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
It's pure C.
strangerstill is offline   Reply With Quote
Old January 6th, 2003, 06:19 PM     #10 (permalink)
Senior Member
 
Join Date: Oct 2001
Posts: 881
Send a message via AIM to zskillz
thx... don't know that at all!... if it's simple (and I assume it is), can you just write a quick java translation of that so that I understand what you're doing?

if not!!! no biggie.

-Z
zskillz is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2978)
The disrespect of Obama by Russian .. (46)
Making Health Care Worse (181)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
Regular Build (11)
windows 7 problem (7)
Laptop with wireless problem. (5)
windows vista security holes (13)
Is the PSU I received dead? (13)
Point and Shoot Camera Suggestions. (5)
Print spooler problem (16)
radeon x850xt platinum & shader.. (6)
HIS HD5770 graphic card question (15)
Recent Discussions
CPU fan stops spinning randomly (11)
Nvidia GTX 260 problem (1)
Modern Warfare 2: Who Bought It? (65)
Point and Shoot Camera Suggestions. (5)
Is the PSU I received dead? (13)
Print spooler problem (16)
windows vista security holes (13)
Kingston Bluetooth Dongle Driver (1)
Multiple Restarts Required at Boot (3)
Open With ..... Win7 (1)
webcam (0)
upgrade for hp a6101 (0)
Laptop with wireless problem. (5)
tv not turn on-makes clicking sound (2)
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Internet Lost (3)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)


All times are GMT -4. The time now is 11:28 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28