Question: Use R programming Write a program that given a positive integer n , finds the Collatz hailstone sequence for that number, and writes a file

Use R programming
Write a program that given a positive integer n, finds the Collatz hailstone sequence for that number, and writes a file giving a report on the sequence. The name of the file (for given n) should be collatz-n.txt. So if n=17, the file should be named collatz-17.txt. The report should include n, the length of the sequence (before it terminates with a 1), and the sequence itself. For example, the report for n=17 should contain:
number: 17
length of hailstone sequence: 13
sequence:
17,52,26,13,40,20,10,5,16,8,4,2,1
Try n=27.(The sequence is rather long.)
Hints: The function converts numerical values to character strings. For example, format (17) is "17". Use the function to create the needed file name.
paste
 Use R programming Write a program that given a positive integer

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!