Sorting using the Collatz Conjecture

I was curious if the Collatz Conjecture could be utilized to become a valid sorting algorithm, so I wrote up some notes and solved out a list of six numbers. But first, here’s the approach I used:


As you might guess, this is an incredibly inefficient sorting algorithm. However, based on my notes, it seems like it has promise. I decided to implement it in python, because it’s python.

Here’s the code, with periods for whitespace:

# Array of original numbers to sort
sortMe = [14, 31, 7, 43, 3, 13]
sortedMe = []
run = True
# copy over the original values
copy = []
for i in sortMe:
run = False
for y in xrange(len(copy)):
run = (run or (copy[y] != 1))
for x in xrange(len(copy)):
temp = copy[x]
if(temp == 1):
if(sortMe[x] != 0):
sortMe[x] = 0
elif(temp % 2 == 0):
temp = temp / 2
elif(temp % 2 != 0):
temp = ( 3 * temp ) + 1
copy[x] = temp

So, I ran this, giving me the result:

[3, 13, 7, 14, 43, 31]

…Well, shucks. Turns out the Collatz Conjecture is not a valid sorting algorithm.

Thanks for Reading!


Growing Mountains from Math

This week, I did two things. A) Got bored and made a wordpress blog, and B) Wondered how to model a mountain.

I started out researching various base points to start from. I imagined a mathematical model for a mountain being vaguely like a normal distribution, peaked at (0, 0), and the limit at infinity would be zero. I tried various curves, until I mistakenly found the Lorenz Hat equation (Which I now can’t find the source).

f(x,y) = \frac{1}{x^2 + y^2 + 1}

Now, this gave me a nice, tidy hat type deal.


Nice, but not nearly noisy enough for a mountain. I then added some “noise” functions, like cos(x*y), etc.


This was nice, but I also wanted a much higher render quality. At this point, I switched over to Blender to do the heavy lifting (Rendering-wise).

First, to export it, I created a gray scale image using mathematica:


After getting the map, I used Gimp to edit it. It took a lot of Gaussian Blurring, but I managed to “smooth” it out mathematically.


Next, I created a Mesh in Blender, then used a displace modifier. I received the displacement data from the texture above, this resulted in a much nicer looking deal.


Here’s a view from the top down. I love how you can still partially see the cos(x*y) in the mapping.Image

Lastly, here’s a beauty shot with a mildly realistic texture.


Thanks for reading!

– Tsoccer93