Archive for the ‘Uncategorized’ Category

Emacs or vi?

Thursday, May 6th, 2010

Text editors are a topic of much contention amonst programmers. Sometimes it can get pretty emotional. I’ve heard that debates over the merits of competing text editors have at times come to blows.

Today I decided to resolve this age-old question once and for all. Which is better: emacs or vi? I sent a simple poll out on Reddit, and received 279 responses. Below I have summarized the results in chart form.

Vi users outvoted emacs users two-to-one. Sorry emacs, but charts don’t lie. Looks like vi is the superior text editor. :-)

The Next AI Challenge

Thursday, April 29th, 2010

In the last day or so, I have started seriously working on the next AI Challenge, which I hope to launch in early May. The first step is to choose a game to use for the contest. This morning I came up with a short list of decent two-player strategy games, and created a Google Form to allow people to vote for their favorites. After posting the form on Reddit, I managed to get almost 600 votes in a fairly short period of time. Here are the results.

Clearly, Chess is a terrible idea. Aside from that, all the other games are completely tied. Go seems to be slightly ahead, but that could just be a fluke. Overall, these results don’t seem to be very helpful. How should I decide which game to pick?

The Statistics of Sex Tapes

Monday, April 26th, 2010

How long would it take to watch all the porn in the world? Is it even possible? This is what my friends and I were wondering the other day at the pub. Being a bunch of math students, we whipped out a pocket calculator to find out. Here’s what we came up with.

To produce a really conservative estimate, let’s restrict ourselves only to amateur sex tapes produced by couples in the United States. How many are there? How long would it take to watch them all if it was your full-time job? There are currently 307 million people in the United States. Suppose that two-thirds of people will at some point be part of a couple. That’s 102 million couples. Suppose that only 5% of these couples will ever produce a sex tape. That’s 5 million sex tapes produced by people who are currently living in the US. Given that the average life expectancy is 78 years, we can err on the safe side by assuming that about 1.3% of those sex tapes will be made this year. Add that all up, and we can safely assume that 65,598 sex tapes will be made in the US this year.

By taking a straw poll, we guessed that the average sex tape would be 10 minutes long after editing, but let’s call it 5 just to be sure. Therefore 327,991 minutes of sex tape will be produced this year. If you unrolled that much VHS tape, it would stretch between Toronto and Montreal. If you put all that porn onto DVDs, it would make a stack 13 stories high. So, is it feasible to watch that much porn?

If watching porn was your full-time job (40 hours per week, all year round, no holidays), you would only be able to watch 38% of the amateur sex tapes made this year in the United States alone. The more you watch, the further behind you fall. I conclude based on this analysis that it is absolutely impossible to watch all the porn in the world.

A Very Special Prime Number

Friday, April 9th, 2010

357686312646216567629137 is a very special prime number. Why is it so special, you ask? Because all of its suffixes are also prime numbers.

Isn’t that cool? 7, 37, 137, 9137, and so on are all prime numbers!

I call these sorts of prime numbers suffix primes. Their existence was pointed out to me by a friend in a Facebook comment. There are exactly 4260 suffix primes that do not contain zeros, and the above number is the largest. But what if we count the suffix primes that do contain zeros? How many are there? Are there perhaps infinitely many? What about prefix primes?

Tron Games

Monday, March 1st, 2010

I just finished running a large programming contest called the Google AI Challenge. By popular request, I am posting a complete log of all the games that were played in order to determine the final rankings.

The complete record can be found here: www.jpcameron.com/tron/tron-games.zip.

More Addictive than Nicotine

Saturday, February 27th, 2010

When I set out to design this year’s Google AI Challenge, one of my priorities was the make the contest as addictive as possible. I didn’t have to look far for inspiration. All I had to do was borrow a few tricks from the Big Tobacco marketing playbook.

  1. Get them hooked early. In order to deliver the first fix as quickly as possible, I posted a five-minute quickstart guide with instructions on how to get your name onto the global leaderboard in less than five minutes. I posted some simple working entries on the website which could be directly re-submitted without any modifications. Cigarette companies use Joe Camel to advertise to children, drug dealers offer free doses to lure first-time users, and the contest has Starter Packages.
  2. Instant gratification. In last year’s Google AI Challenge, people would have to wait between one and two hours to see their latest submission’s ranking. This means that if it’s 3:00 AM and you just submitted your code, there is a fairly large incentive to go to bed. This is clearly unacceptable. This year, participants were able to see their new ranking within at most five minutes. By shortening the feedback loop to almost nothing, we set up a situation that is very similar to a gambling addict at a blackjack table. Just one more hand…
  3. Lace it with addictive chemicals. Despite much effort, I was not able to figure out how to lace the contest with addictive chemicals. That being said, I am fairly sure that time spent working on the contest is highly correlated with intake of caffeine and MSG.

Cigarette companies use Joe Camel to advertise to children, drug dealers offer free doses to lure first-time users, and the contest has Starter Packages.

After all was said and done, I believe that my efforts paid off. Here are a few quotes from contestants, taken the day after the submission deadline:

“I’m glad the deadline wasn’t extended, i was sleeping better last night than the previous dozens of night. i was constantly working on it, that is finally over :)

“actually I dreaded the deadline getting extended. I am really happy it’s over. my obsessive-compulsive behaviour would have continued for some time”

“I am glad that this is finally finished too, or wife is going to get grumpy. (unrecognizable yelling at the background)”

So… Close…

Thursday, February 25th, 2010

Most people can imagine the joy that comes from watching the odometer of an old truck roll over.

It's like your 50th wedding anniversary, except better.

In the last couple days, I’ve been approaching a milestone of my own. The traffic for the Google AI Challenge website has been approaching our initial dream goal of 1,000,000 pageviews. This morning I got out of bed and immediately checked it, what with my being a Google Analytics addict. Here is how I found it:

So... close...

Couldn’t have cut it any closer than that. Looks like today is going to be the big day.

Genetic Algorithm Art Fail

Wednesday, February 24th, 2010

Today I have started an experiment to use a Genetic Algorithm to create artistic drawings. I hope to achieve results similar to Bergen and Ross from Brock University. As a test, I tried approximating the Mona Lisa in grayscale using only circles. Here is the result.

Fail.

While this is an interesting image, it doesn’t look a lot like the Mona Lisa. Some of the largest features of the Mona Lisa are present to a degree, such as a light region in the center, dark bottom corners, and a light top-right corner. However, I wouldn’t call this a success.

What went wrong? I believe that the set of genetic operators I chose (the Galib defaults) are not appropriate, especially the mutation operator. I will implement some new ones that make more sense and try again. Hopefully the results improve.

For the Genetic Algorithms, I am using Galib. For the image manipulation code, I am using CImg.

CImg Image Library for C++

Wednesday, February 24th, 2010

Today I started playing around with the CImg library. It’s a library for C++ which can read and write image files in many common formats, and also manipulate images in memory. I want to use it for some specific computer art projects that I have had in mind for a little while.

As a test to familiarize myself with the CImg API, I constructed the following image. It’s a bunch of multicolored semi-transparent circles placed in a golden ratio spiral pattern. Click the image for a bigger version.

A golden ratio spiral pattern, using multicolored semi-transparent circles

The Collatz Conjecture

Friday, February 19th, 2010

I have been fascinated by the Collatz conjecture for years. It’s a math problem that is so simple to understand, yet no mathematician has managed to solve it. Since the problem was first proposed by Lothar Collatz in 1937, many mathematicians have gone crazy trying to solve it. Here’s how it works.

The Collatz function takes one number, denoted by n, and turns it into another number. If n is even, the result is n/2. If n is odd, the result is 3n+1. For example, if n is 3 then the result is 10. If n is 4 then the result is 2. If n is 5 then the result is 16. You get the idea.

A Collatz sequence is formed by starting with a number, and repeatedly applying the Collatz function to extend the sequence. For example, the Collatz sequence for n=3 is 3-10-5-16-8-4-2-1. The Collatz sequence for n=5 is 5-16-8-4-2-1. The Collatz sequence for n=2 is just 2-1. Here is a picture of the sequences for n=7 and n=19.

After looking at some of these sequences, you may start to notice a pattern. No matter how high they go, they always seem to come back down to 1. Does every Collatz sequence always come back down to 1? Perhaps some of them get into a loop and keep going round forever, or perhaps some of them just keep going up and up towards infinity. This is the Collatz conjecture: prove that every Collatz sequence eventually comes back down to 1.

Another way to picture the problem is using total stopping times. The total stopping time of a number is the number of steps it takes for the number’s sequence to reach 1. The Collatz conjecture states that every number has a finite stopping time. Despite being such a simple problem, and being open for almost 75 years, nobody has managed to prove or disprove the Collatz conjecture.

There are a couple really tantalizing patterns in the total stopping times. Let me show you just one. Have a look at the first 1000 stopping times.

The first 100 total stopping times. The horizontal axis is n, and the vertical axis is the total stopping time of n.

Notice any patterns? It looks like some of the points are bunching up into short horizontal lines. Furthermore, these short horizontal lines seem to line up in large sweeping curves. To investigate these patterns further, I wrote a short C++ program to draw the same chart, except for the first ONE BILLION stopping times. This time, the x-axis is logarithmic.

The first one-billion total stopping times. The horizontal axis is n, and the vertical axis is the total stopping time of n.

Whoa, now that’s a pattern! Look at all those nice straight lines. Check out a closeup of the bottom-right part of that image.

Close-up of the patterns in the total stopping times

What is causing all those straight lines? Why are they all the same length? The most interesting question to me is, why is there always a long “dash” followed by a short “dot”? If we can explain the structure of these regular patterns, can we construct an exact probability distribution for the total stopping time of any number? Could this distribution be the key to finally proving or disproving the Collatz conjecture? If you want to do a bit of work on the Collatz conjecture, answering these questions might be a good place to start.