Humane Software

Posted on August 10th, 2008

I have had my Squeezebox for a good while now but I just discovered that I have been missing its best feature.

Squeezebox comes with SqueezeCenter - a piece of software that lets you remote control your Squeezebox from a PC.You can stream music from your hard drives or iTunes or any number of internet radio stations or subscription services. But the best bit is that SqueezeCenter is hackable.

SqueezeCenter is open source and has a plugin model and there are tons of plugins for it. Here’s my favourite:

Do you ever find you’re in the middle of listening to your favourite track when your other half suddenly announces that the volume is far too loud and turns it down for you? If so, this may be the plugin for you! VolumeGuard detects “unauthorised” changes in volume and stealthily restores the volume to its original level. Changes are made in small increments over a period of time, so with any luck they won’t notice!

I have wished for that since forever! Well done, writer of VolumeGuard!

Problem 12

Posted on June 22nd, 2008

To save you going all the way to Project Euler to read it, I have copied problem 12 here for your puzzle solving convenience…

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28.

The first ten terms would be:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …

Let us list the factors of the first seven triangle numbers:

1: 1
3: 1,3
6: 1,2,3,6
10: 1,2,5,10
15: 1,3,5,15
21: 1,3,7,21
28: 1,2,4,7,14,28

We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?

In case you were wondering, the answer to problem 10 is


primes = Primes.new
puts primes.find_primes_less_than(2000000).inject{|s,n| s+n}

How come inject and collect haven’t caught on in other languages? They are awesome.

Forgetful me

Posted on June 21st, 2008

According to Kurzweil, the singularity (the moment when we will start to invent things instantaneously) will occur in 2045. According to me the singularity (the moment when I forget things fast than I can learn things) occurs in 2009.

Every time I start over with Ruby (or XSLT or …) I find that I have forgotten the most basic things (like how to construct an object).

Anyway, thanks to Project Euler (according to which, I am 4% genius), I had an excuse to go go back and learn Ruby all over again.

Here’s my prime number generator (which is about a third of the size of my Java version):


class Primes
  def initialize
    @primes = []
    @next_candidate = 2
  end

  def prime? number
    root = Math.sqrt number
    find_primes_less_than root

    @primes.each do |prime|
      return true if prime > root
      return false if number % prime == 0
    end
  end

  def find_primes_less_than limit
    until @next_candidate > limit
      @primes << @next_candidate if prime? @next_candidate
      @next_candidate += 1
    end
  end

  def [] index
    until @primes.size > index
      find_primes_less_than @next_candidate + 100
    end
    return @primes[index]
  end
end

The answer to problem #7 is @primes[10000], in case you were wondering.

Wasting Time

Posted on June 15th, 2008

Project Euler. Wasting time with Maths.

My attempt at #3 is running now (which probably means it is wrong).

Monty Hall in Squeak

Posted on May 4th, 2006

Over at www.developertesting.com, I wrote about the Monty Hall problem and how I was convinced of the answer by an unused variable in my Java simulation.

Markus wrote a nice simulation in Squeak (dunno what it will do if you don’t have squeak installed but it makes a good excuse for you to go get it).

click for bigger image

I am always on the lookout for ideas for a science project for Dylan. For me, the ideal kid’s science project has a hypothesis that

  1. will almost certainly be wrong
  2. can be tested empirically
  3. can be proven mathematically

with extra credit if you can write a computer simulation of it. Dylan’s project last year was “What should you do if draw three cards to an inside straight in poker?”. He said you should raise. I usually beat him at poker :-)