Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

=+ Why have these changes occurred?

Answered: 1 week ago

Question

=+90 percent of all oil refineries) into several smaller companies

Answered: 1 week ago