Collatz sequence/Program/Exercise

From Wikiversity
Jump to navigation Jump to search

Write a computer-program (in pseudocode) which, for a given natural number , computes the corresponding Collatz sequence, and stops, when it reaches .

    • The computer has as many memory units as needed, which can contain natural numbers.
    • It can empty memory units.
    • It can increase the content of a memory unit by .
    • It can write the content of a memory unit into another memory unit.
    • It can add the content of two memory units and write the result into another memory unit.
    • It can compare the content of memory units and can, depending on the outcome, switch to a certain program line.
    • It can print contents of memory units and it can print given texts.
    • There is a stop command.

The initial configuration is

The program is supposed to print out the Collatz sequence starting with and to stop when is reached.