Ok guys, I\'ve got a programming dilemma I just cannot figure out. It\'s for my
ID: 3808652 • Letter: O
Question
Ok guys, I've got a programming dilemma I just cannot figure out. It's for my visual basic programming class.
Here's the assignment: The dog starts at node 5 (dogs value is 5) and escapes the tunnel at node 1 or node 9. If the dog hits node 2 a force of nature propels it to node 7. How long does the dog stay in the tunnel if it takes 1 minute to move between nodes? Count the total moves (minutes) of all the dogs by restarting a dog at node 5 one thousand times. Calculate the average time it takes the 1000 dogs to exit the tunnel. The form should have a Start Dog button and a Label to display the average number of minutes the 1000 dogs took to escape.
I don't necessarily want the entire code written for me, I'm moreless asking for adivce on how to go about it or maybe an example? Any advice on how to best attack this would be great. I honestly think I am over thinking this entire thing. I get confused on loops and random numbers as I was told not to modify loop variables as I have mistakenly done in the past.
Thanks to any advice!
Explanation / Answer
I am not sure how the dog would move...is it intelligent? Does it move back once it crosses a node? Anyway, assuming the dog moves completely random way, I can write the pseudocode as follows:
total_time_for_all_iterations = 0
Loop 1000 times {
dog_position = 5
while (dog_position is not node1 or node9) {
time_for_current_iteration = 0
go_left = random number between 0 and 1 // 1 will denote yes, 0 will denote no
if go_left is 1 {
dog_position = dog_position - 1 //go left
}
else {
dog_position = dog_position + 1 // go right
}
time_for_current_iteration = time_for_current_iteration + 1 // travel time is 1 minute, so increment
}
total_time_for_all_iterations = total_time_for_all_iterations + time_for_current_iteration
}
average_time = total_time_for_all_iterations / 1000
return average_time
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.