Free Republic
Browse · Search
Bloggers & Personal
Topics · Post Article

To: zeugma

If you have an odd number, multiplying it by 3 and adding one would produce an even number.

7 22 11

If you have an odd number, add to it half of the preceding number. Add one.

7 10 11

Don’t write the intermediate step.

7 11

You have an odd number. How many consecutive odd numbers follow it?

Wtite a number as a sum of powers of 2.


65 posted on 10/06/2021 7:02:44 PM PDT by TTFX ( )
[ Post Reply | Private Reply | To 64 | View Replies ]


To: TTFX

# Wtite a number as a sum of powers of 2.

Uh, it’s a shell script, not a program. :-)

Here’s another version that bails out on any number lower than itself. You can put together the whole path by jumping from the last number in the string to where it was calculated.

1

2 1

3 10 5 16 8 4 2

4 2

5 16 8 4

6 3

7 22 11 34 17 52 26 13 40 20 10 5

8 4

9 28 14 7

10 5

11 34 17 52 26 13 40 20 10

One of the thing I find to be interesting is that there doesn’t seem to be much rhyme or reason to the number of steps it takes for any series of consecutive numbers. In the below you can see that 27 is a big outlier.

zprc:~ :) collatz2 10 30 | grep step
10 takes 6 steps, and 16 is the highest number reached.
11 takes 14 steps, and 52 is the highest number reached.
12 takes 9 steps, and 16 is the highest number reached.
13 takes 9 steps, and 40 is the highest number reached.
14 takes 17 steps, and 52 is the highest number reached.
15 takes 17 steps, and 160 is the highest number reached.
16 takes 4 steps, and 16 is the highest number reached.
17 takes 12 steps, and 52 is the highest number reached.
18 takes 20 steps, and 52 is the highest number reached.
19 takes 20 steps, and 88 is the highest number reached.
20 takes 7 steps, and 20 is the highest number reached.
21 takes 7 steps, and 64 is the highest number reached.
22 takes 15 steps, and 52 is the highest number reached.
23 takes 15 steps, and 160 is the highest number reached.
24 takes 10 steps, and 24 is the highest number reached.
25 takes 23 steps, and 88 is the highest number reached.
26 takes 10 steps, and 40 is the highest number reached.
27 takes 111 steps, and 9232 is the highest number reached.
28 takes 18 steps, and 52 is the highest number reached.
29 takes 18 steps, and 88 is the highest number reached.
30 takes 18 steps, and 160 is the highest number reached.


67 posted on 10/06/2021 8:10:36 PM PDT by zeugma (Stop deluding yourself that America is still a free country.)
[ Post Reply | Private Reply | To 65 | View Replies ]

Free Republic
Browse · Search
Bloggers & Personal
Topics · Post Article


FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson