Andyman's Golf Course - Hole 5 - Collatz Conjecture

View as PDF

Submit solution


Points: 0
Time limit: 1.0s
Memory limit: 256M

Author:
Problem types
Allowed languages
Python

For the fifth hole of AndyMan68's golf course, he would like you to examine the Collatz Conjecture.

The Collatz Conjecture is based on a series of operations applied on a number, as described by the function below:

\[ f(n) = \begin{cases} \frac{n}{2} & \text{if } n \:\text{is even},\\ 3n+1 & \text{if } n \:\text{is odd},\\ \end{cases} \]

It is conjectured that if this function applied over and over again for any positive integer, it would eventually converge to 1 (and then repeat a cycle of 1\rightarrow4\rightarrow2\rightarrow1).

You are to write a program to follow the process described above on all numbers from 1 to 50 inclusive. For each number from 1 to 50 inclusive, your program should output the sum of all the numbers it reaches (including the starting number) before it reaches 1.

For example, if 3 was the starting number, the process would proceed as follows:

  • 3\rightarrow10\rightarrow5\rightarrow16\rightarrow8\rightarrow4\rightarrow2\rightarrow1

Starting with 3, your program should output 3+10+5+16+8+4+2=48.

Input Specification

There is no input.

Output Specification

Your program should output all 50 sums for this process starting with the numbers from 1 to 50 inclusive, on a single line separated each by a single space.

More specifically, the output should be (on a single line):

0 2 48 6 35 54 287 14 338 45 258 66 118 301 693 30 213 356 518 65 147 280 632 90 657 144 101439 329 441 723 101103 62 840 247 539 392 534 556 2343 105 101330 189 1337 324 496 678 100978 138 805 707

Scoring

If the program has the correct output, you will receive a score of:

  • 0 if the length of the code in bytes exceeds 150
  • 100 if the length of the code in bytes is less than 71
  • (171-N)\times \frac{71}{N} where N is the length of code in bytes, if 71\le N \le 150

Comments

There are no comments at the moment.