• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Programming help, please!

Kromis

Diamond Member
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?
 
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.
 
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. 😛
 
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
 
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!
 
i have no life

i made enhancements


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