Free Republic
Browse · Search
General/Chat
Topics · Post Article

To: onedoug
Here's one that will even interest kids. It's called the Collatz Conjecture.

You may start with any number.

   If the number is odd, multiply it by 3 then add 1.

   if the number is even, divide by two.

Take the number you end up with and repeat. Eventually you will end up with the number 1.

I wrote a script to play with this a bit. Here are a few examples of the output:

$ collatz 10
10 5 16 8 4 2 1
Starting with the initial value of 10, it takes 6 steps to reach unity.
$ collatz 25
25 76 38 19 58 29 88 44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
Starting with the initial value of 25, it takes 23 steps to reach unity.
$ collatz 26
26 13 40 20 10 5 16 8 4 2 1
Starting with the initial value of 26, it takes 10 steps to reach unity.
$ collatz 27
27 82 41 124 62 31 94 47 142 71 214 107 322 161 484 242 121 364 182 91 274 137 412 206 103 310 155 466 233 700 350 175 526 263 790 395 1186 593 1780 890 445 1336 668 334 167 502 251 754 377 1132 566 283 850 425 1276 638 319 958 479 1438 719 2158 1079 3238 1619 4858 2429 7288 3644 1822 911 2734 1367 4102 2051 6154 3077 9232 4616 2308 1154 577 1732 866 433 1300 650 325 976 488 244 122 61 184 92 46 23 70 35 106 53 160 80 40 20 10 5 16 8 4 2 1
Starting with the initial value of 27, it takes 111 steps to reach unity.
$ collatz 28
28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
Starting with the initial value of 28, it takes 18 steps to reach unity.
$ collatz 29
29 88 44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
Starting with the initial value of 29, it takes 18 steps to reach unity.
 

Look up the wiki entry for the Collatz Conjecture. It has some interesting stuff on plotting the number of steps as well. Here's a variation, where we're not interested in the numbers returned, but instead are interested in the number of steps and the highest number reached in the series. For some reason 9232 is a really common mumber you see as the highest number, which you'll find if let the program chomp on a few thousand numbers

$ collatz2 2 40 | grep highest
2 takes 1 steps, and 2 is the highest number reached.
3 takes 7 steps, and 16 is the highest number reached.
4 takes 2 steps, and 4 is the highest number reached.
5 takes 5 steps, and 16 is the highest number reached.
6 takes 8 steps, and 16 is the highest number reached.
7 takes 16 steps, and 52 is the highest number reached.
8 takes 3 steps, and 8 is the highest number reached.
9 takes 19 steps, and 52 is the highest number reached.
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.
31 takes 106 steps, and 9232 is the highest number reached.
32 takes 5 steps, and 32 is the highest number reached.
33 takes 26 steps, and 100 is the highest number reached.
34 takes 13 steps, and 52 is the highest number reached.
35 takes 13 steps, and 160 is the highest number reached.
36 takes 21 steps, and 52 is the highest number reached.
37 takes 21 steps, and 112 is the highest number reached.
38 takes 21 steps, and 88 is the highest number reached.
39 takes 34 steps, and 304 is the highest number reached.
40 takes 8 steps, and 40 is the highest number reached.
 

Fun with numbers!

16 posted on 01/21/2014 8:39:41 AM PST by zeugma (Is it evil of me to teach my bird to say "here kitty, kitty"?)
[ Post Reply | Private Reply | To 1 | View Replies ]


To: zeugma

Indeed.


17 posted on 01/21/2014 8:42:06 AM PST by onedoug
[ Post Reply | Private Reply | To 16 | View Replies ]

To: zeugma

Do you suppose there might be a finite number of highest numbers?


23 posted on 01/21/2014 11:03:10 AM PST by Marylander
[ Post Reply | Private Reply | To 16 | View Replies ]


36 posted on 12/28/2023 10:31:44 AM PST by SunkenCiv (Putin should skip ahead to where he kills himself in the bunker.)
[ Post Reply | Private Reply | To 16 | View Replies ]

Free Republic
Browse · Search
General/Chat
Topics · Post Article


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