How Many Edges Will Herman Visit Before Reaching the Poison?

  • Thread starter Thread starter Demon117
  • Start date Start date
  • Tags Tags
    Coding
Click For Summary

Discussion Overview

The discussion revolves around a programming problem involving a simulation of a fly named Herman navigating the edges of a cube. Participants are addressing the requirements for the simulation, including how to track Herman's movements and determine when he reaches the poison. The conversation includes aspects of algorithm design, coding practices, and debugging.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant shares an incomplete code snippet for the simulation and expresses confusion about its functionality.
  • Another participant points out that the function isHermanDead will always return true due to a coding error.
  • Some participants emphasize the importance of developing one's own algorithm before seeking examples, suggesting that this approach fosters better learning.
  • There is a challenge to the original poster's intent, with some participants expressing concern that asking for examples may imply a lack of effort in creating a solution.
  • One participant suggests that the original poster should focus on understanding the problem requirements rather than looking for similar examples.

Areas of Agreement / Disagreement

Participants generally agree on the importance of developing one's own understanding and algorithm for the problem. However, there is disagreement regarding the original poster's approach to seeking help and the implications of their request for examples.

Contextual Notes

Some participants note that the original code lacks sufficient functionality and clarity, and there are concerns about the use of global variables and the need for well-defined functions. The discussion highlights the need for clearer problem-solving strategies and coding practices.

Who May Find This Useful

This discussion may be useful for students learning programming concepts, particularly in the context of simulations and algorithm development, as well as those seeking advice on debugging and coding practices.

Demon117
Messages
162
Reaction score
1

Homework Statement



Consider Herman the Fly. Herman must exist on the edges of a cube. At the start of a trial, Herman is randomly placed on one of the eight corners of a cube and poison is placed on one of the eight corners. Herman starts moving along one of the three edges. When he comes to a corner, he chooses one of the two other edges and continues. When he reaches the corner with the poison, he dies. How many edges will Herman visit before he hits the poison? Note that Herman may possibly visit zero to an infinite number of edges in a given trial.

The cube corners are labeled from 0 to 7 with 0 starting at the upper left hand corner of the front fact proceeding clockwise with corners 0, 1, 2, and 3 on the front face, and corner 4 being the upper left hand corner of the rear face and proceeding clockwise with corners 4, 5, 6, and 7 on the rear face.

Develop a simulation of Herman's travels around the cube. For each trial, print out the initial corners of Herman and the poison and all the corners Herman visits until reaching the corner with the poison. Then display the total number of corners visited by Herman in this trial and a running average of the number of corners Herman reached in all trials since the program with initiated. Then ask the user if another trial is desired.

Insufficiently commented code, poorly chosen variable or function names,. not using functions sufficiently or appropriately, using global variables when not required, nor not passing the correct information into a function, etc. will reduce one's grade. Each function requires a block comment stating your name, a single sentence (sans "ands" or "ors") stating the purpose of that function, as well as a description of the parameters (if the names are insufficient). Don't use global variables to avoid passing parameters. An acceptable solution will have at least 10 functions.



The Attempt at a Solution



This is all that I have:
Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <cmath>
using namespace std;

bool isHermanDead(int pos1,int pos2)//
{
     if (pos1=pos2)
        cout<<"Herman is Dead"<<endl;
     else
         cout<<"Herman is alive"<<endl;
}

int main()
{
    srand( time(NULL) );
    int poisonPos = rand()%10;
    int hermanPos = rand()%10;
    
    bool heDead = isHermanDead(hermanPos, poisonPos);
    cout<<"The result is that "<<heDead<<endl;
    
    system("pause");
    
    return 0;
}

This is all that I have for the program so far. But apparently I have something amiss here. Does anyone know of examples out there that are similar in nature to this problem?
 
Physics news on Phys.org
matumich26 said:
But apparently I have something amiss here.
Uh, yeah. "Something amiss" is a bit of an understatement.

Does anyone know of examples out there that are similar in nature to this problem?
You don't learn by copying. You learn by doing. Start learning.Show some work on your own. What you have done so far does not qualify as such.
 
You don't have much to go on, yet.

One comment: your isHermanDead function will always return true, no matter what pos1 and pos2 are.

Do you have an algorithm that you're going to implement in code? One instructor I had years ago said, "The sooner you sit down to the keyboard, the longer your program will take to write." It looks like you have sat down to the keyboard too soon, without having a clear idea of what your program needs to do.

Instead of looking for examples that may or may not be similar, it would be better to figure out what you need to do in this problem.
 
D H said:
Uh, yeah. "Something amiss" is a bit of an understatement.


You don't learn by copying. You learn by doing. Start learning.


Show some work on your own. What you have done so far does not qualify as such.

That was never my intent sir. Just because I ask for examples does not assume I am going to copy said examples. Please do not undermine my intelligence by assuming such things. I did not want to include anything that was irrelevant to the problem at hand. That being said, no one learns by ignorance either.
 
matumich26 said:
I did not want to include anything that was irrelevant to the problem at hand.
But any parts that are relevant get used, right?

I'm with D H on this. Start by devising your own algorithm, and then writing functions that implement it. You will learn a lot more by coming up with your own solution than by looking at someone else's. When you get further along (a lot further along), and have run into problems, let us know, and we'll give you a hand.
 

Similar threads

Replies
8
Views
3K