Hi! I'm John...

Thinkhole Labs I'm an engineer, but sometimes I like to pretend I'm a programmer. Current obsessions include Ruby and Project Euler.

01 December 2009 | 0 Comments

Animated Collatz sequence using Gosu

Continuing my obsession with the Collatz conjecture, I took some of my Ruby code from the other day and mixed in some Gosu 2D animations.

Basically, I randomly seed a bunch of objects and then let them bounce their way through the sequence until they bottom out at 1, and then drop them. There’s a counter in the top left that shows how many are left.

Anyway, here’s the video with the obligatory iMovie stock music in the background:

The little monster blocks are a free icon set from Fast Icon. I’m a huge fan. :)

12 November 2009 | 2 Comments

Dropbox and Ubuntu One

I did a talk on Dropbox and Ubuntu One at the CPLUG meeting on Tuesday night. The slides are online:

cplug_dropbox_112009_001-001

I was surprised that no one had heard of Ubuntu One even though quite a few people in the room were running Ubuntu 9.10.

07 November 2009 | 2 Comments

Gosu tutorial

Ran through the Gosu Ruby Tutorial tonight…

I’m having a lot of fun with this. :)

04 November 2009 | 1 Comment

Apple iMac flickering display

I recorded some video of the intermittent display issues I’ve been having with the new 27″ iMac. You can see examples of both the horizontal white static/noise (need to watch carefully to see it in the video) and the complete screen blanking:

There’s a second video showing similar problems as well.

Looks like this is not uncommon, and the procedure is to take it back to the Apple store and they’ll replace it. That’s cool, but still kind of a pain.

31 October 2009 | 1 Comment

Calculate a hailstone sequence

One of the Project Euler problems deals with the Collatz conjecture, which can basically be summed up like this:

We take any whole number n greater than 0. If n is even, we halve it (n/2), else we do “triple plus one” and get 3n+1. The conjecture is that for all numbers this process converges to 1.

So you start with some seed number (n) and keep moving to the next number in the sequence by either dividing by two or multiplying by three and adding one. If you start with 1, you’d get 1, 4, 2, 1. If you start with 5, you’d get 5, 16, 8, 4, 2, 1. The reason these are also known as “hailstone sequences” is because the numbers rise and sink like ice in an thunderstorm cloud. Every number ever tested has always ended up falling to 1, but it’s never been mathematically proven that every number does the same.

Anyway, here’s some Ruby that, given a seed (n), will yield each number in the sequence and return the total length:

I added a few lines to write the output to a .csv file and then plotted it (n=27) using R:

hailstone27

That’s 112 data points going as high as 9232 before eventually dropping down to 1.

Tags: , , ,