Question

In this project, you will write C code to solve the Collatz conjecture using ordinary pipes...

In this project, you will write C code to solve the Collatz conjecture using ordinary pipes to share data between parent and child processes

Here are the rules for your program:

  1. The starting number will be entered on the command line. Be sure to check that it is positive.
  2. The parent will handle the command line and pass the integer to the child.
  3. The child will do the calculation and pass the sequence generated back to the parent.
  4. The parent will invoke wait while the child is doing the calculation.
  5. The parent will print out the sequence generated.

Homework Answers

Answer #1

public static string collatz(string y)

{

if (y == null)

{

return null;

}

int x = int.Parse(y); //x is my "n"

var results = new StringBuilder();

results.Append(x.ToString());

int largest = x; //keep track of biggest number

// the algorithm

// the redundancies (like x==1.. x!= 1) are part of troubleshooting :/

while (x > 1)

{

if (x % 2 == 0)

{

x = x / 2;

if (x > largest)

{

largest = x;

}

if (x != 1)

{

results.Append(" " + x.ToString());

}

if (x == 1)

{

results.Append(" " + x.ToString());

results.Append(" largest number was " + largest.ToString());

return results.ToString();

}

}

if (x % 2 != 0)

{

if (x == 1)

{

results.Append(" " + x.ToString());

results.Append(" largest number was " + largest.ToString());

return results.ToString();

}

x = (3 * x) + 1;

if (x > largest)

{

largest = x;

}

results.Append(" " + x.ToString());

}

}

return results.ToString();

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Client / Server using named pipes with thread and fork() in C/C++ **Note** You will need...
Client / Server using named pipes with thread and fork() in C/C++ **Note** You will need to write a client program and a server program for this question to be correct. ** **Cannot use socket** client the client application that will get the command from the user and pass the command to be executed from the command line, parses the command and puts a binary representation of the parse into a shared memory segment. At this point, the client will...
Compile and run the following code and presuming your executable is in a.out, run this command...
Compile and run the following code and presuming your executable is in a.out, run this command from the shell prompt: ./a.out ; echo "Parent Terminated Normally with a return value of $?" Explain, in your own words, why you see the screen output you do and how that output relates to both the content of the program AND the nature of the shell command used to invoke it. Hint: This has everything to do with how processes “communicate” their exit...
For this assignment you need to write a parallel program in C++ using OpenMP for vector...
For this assignment you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is: #pragma...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
Develop a 2018 individual tax return (with all required forms and supporting schedules) for Rob and...
Develop a 2018 individual tax return (with all required forms and supporting schedules) for Rob and Laura Petrie that is both professional in appearance and technically correct. The use of tax software or a professional tax preparer to complete this project is prohibited. You can access fill-in forms (in pdf format) on the IRS website (www.irs.gov) by clicking on “More” on the left side of the homepage in the “Forms and Pubs” section. Next, click on the “Current Forms and...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From the April 2004 Issue Save Share 8.95 In 1991, Progressive Insurance, an automobile insurer based in Mayfield Village, Ohio, had approximately $1.3 billion in sales. By 2002, that figure had grown to $9.5 billion. What fashionable strategies did Progressive employ to achieve sevenfold growth in just over a decade? Was it positioned in a high-growth industry? Hardly. Auto insurance is a mature, 100-year-old industry...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT