• We should now be fully online following an overnight outage. Apologies for any inconvenience, we do not expect there to be any further issues.

Programming help, please!

Kromis

Diamond Member
Mar 2, 2006
5,214
1
81
Okay, my friend has this program to write but he doesn't how to do it. Here's the problem:

a drunk stands in the middle of an 11-foot bridge. he has a 50% chance of taking a step to the left and a 50% chance of taking a step to the right. draw a picture showing his movements

sample output:

|-----x-----|
|------x----|
|-------x---|
|------x----|
|-----x-----|
|----x------|
|---x-------|
|--x--------|
|---x-------|
|----x------|
|-----x-----|

This type of program is too high of a calibur for me so I can't be of much assistance. He hasn't written his program yet. Well, he doesn't really need to because this problem is supposed to be extra credit but he needs the points.

Could somebody help him?
 

Spydermag68

Platinum Member
Apr 5, 2002
2,616
99
91
He needs a loop for the 11 steps
prints starting point
A random fuction
a mod function
needs to move the x to the right or left
prints line


edit: I am gussing that the drunk could not also take a forward step.
 

Kromis

Diamond Member
Mar 2, 2006
5,214
1
81
Originally posted by: Spydermag68
He needs a loop for the 11 steps
prints starting point
A random fuction
a mod function
needs to move the x to the right or left
prints line


edit: I am gussing that the drunk could not also take a forward step.

Well, he's walking forward and moving left and right. A real drunk would stumble backwards too but this isn't the case. :p
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0
this sounded kinda fun, so i wrote it in php

http://troytime.com/drunk.php

you can override the start position by adding ?start=# to the end of the URL

i simply used a for loop for the length of the bridge, and a for loop inside of that loop to draw the width
and the end of the inner for loop i generated a random number and either moved the position left or right

i'm not sure if i should post the code though, not sure what the 'policy' is
 

Kromis

Diamond Member
Mar 2, 2006
5,214
1
81
Originally posted by: troytime
this sounded kinda fun, so i wrote it in php

http://troytime.com/drunk.php

you can override the start position by adding ?start=# to the end of the URL

i simply used a for loop for the length of the bridge, and a for loop inside of that loop to draw the width
and the end of the inner for loop i generated a random number and either moved the position left or right

i'm not sure if i should post the code though, not sure what the 'policy' is

Thanks troytime!

OMFG! OMFG!!!! YOU ROCK TROYTIME!!!! WOOT!! THANK YOU SO MUCH!

My friend sure will be happy!
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0
i have no life

i made enhancements


thought about converting from ascii to graphic, but my toes are freezin...time to sleep