How Many Edges Will Herman Visit Before Reaching the Poison?

  • Thread starter Demon117
  • Start date
  • Tags
    Coding
In summary, Herman visits edges from 0 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. Herman's travels around the cube are simulated and displayed each time he visits a corner. The user is asked if another trial is desired at the end of the program.
  • #1
Demon117
165
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
  • #2
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.
 
  • #3
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.
 
  • #4
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.
 
  • #5
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.
 

FAQ: How Many Edges Will Herman Visit Before Reaching the Poison?

What is the "Herman the fly coding issue"?

The "Herman the fly coding issue" refers to a coding problem that involves creating a program or script to simulate the behavior of a fly named Herman. This problem is commonly used in computer science and programming courses as a practice exercise.

What is the purpose of the "Herman the fly coding issue"?

The purpose of the "Herman the fly coding issue" is to challenge programmers to think creatively and logically to solve a complex problem. It also helps in improving coding skills and familiarity with programming concepts such as conditionals, loops, and functions.

What programming languages are commonly used to solve the "Herman the fly coding issue"?

The "Herman the fly coding issue" can be solved using any programming language, but it is commonly used as a practice exercise in languages such as Java, Python, and C++. Each language may have its own specific syntax and approach to solving the problem.

What are some common strategies for solving the "Herman the fly coding issue"?

Some common strategies for solving the "Herman the fly coding issue" include breaking down the problem into smaller, manageable tasks, using loops and conditionals to simulate the fly's movement, and using functions to organize and simplify the code. It is also important to test and debug the code to ensure it is functioning correctly.

Is the "Herman the fly coding issue" a real-life problem or just an exercise?

The "Herman the fly coding issue" is primarily used as an exercise or practice problem in the field of computer science and programming. However, it can also be seen as a simplified version of real-life problems that programmers may encounter, such as simulating the behavior of animals or insects for research or educational purposes.

Similar threads

Replies
6
Views
3K
Replies
8
Views
2K
Back
Top