jump to navigation

The longest Chip in the World 18 December 2010

Posted by Oliver Mason in misc.
add a comment

In his Metamagical Themas: Questing for the Essence of Mind and Pattern, Douglas Hofstadter talks about numerical literacy, the ability to understand large numbers. This is especially important when state budgets are through around which deal with billions of pounds or euros. At some point you just lose all feeling for quantities, as they are all so unimaginably large and abstract. He then goes on to pose some rough calculation questions, such as “How many cigarettes are smoked in the US every day?” – you start with some estimates, and then work out an answer, which might be near the order of magnitude of the right answer (which we of course don’t know). Quite an interesting and useful mental exercise.

Yesterday we had Fish & Chips for dinner. The girls were comparing the sizes of their chips, and then we came on to the topic of the longest chip in the world. Obviously, with ‘proper’ chips this is limited by the size of the source potato. However, industrially produced chips are made of mashed potato formed into chip-shapes, so there is not really any fixed limit on the length. So, thinking of Hofstadter, I asked them how many potatoes we would need to make a chip that spans around the whole world.

Rough assumptions: one potato contains enough matter to produce 10cm worth of chip (the thickness is not specified). So, how many potatoes do we need for one metre of chip? This is also useful to practice basic primary-school-level maths… – 10. How many for a kilometre? 10,000. How many kilometres do we need to span the world? Roughly 40,000 km. So how many potatoes do we need? 400 million.

The next question is whether there are enough potatoes in the world to do this. Assuming a potato weighs 100g, how much do our 400 million potatoes weigh? 40 million kilogrammes, or 40,000 (metric) tons. What is the world’s potato production? According to Wikipedia, this is 315 million metric tons, so plenty enough. Now, if we were to turn the annual potato crop into one long chip, how many times would it go round the Earth? 7,875 times.

So, with a bit of basic maths (and Wikipedia for the data) you can make maths exciting for kids, practice how to multiply and divide, teach problem-solving, and have fun at the same time. And they also get a feeling for numbers: 400 million – that’s how many potatoes you need for a chip to span the Earth.


Converting AMR to MP3 29 October 2009

Posted by Oliver Mason in misc.
add a comment

For a teaching project, students were required to audio record a group discussion meeting. For this they could either use a digital recorder, or any other recording equipment they had available. One group used a mobile phone, and we managed to transfer the audio file from the phone to my MacBook using Bluetooth.

Initially I was surprised at the small size of the file: 4.5 MB for a recording of about 50 mins. The quality is of course poor, but AMR does a pretty good job of keeping it small. The equivalent MP3 file comes in at 22.5 MB.

But there was a problem: dealing with AMR files. I cannot load it into my version of Audacity to convert it to MP3, but perhaps there’s a plug-in somewhere. I was not able to immediately find one. Then I found that Quicktime can play back AMR files, and save them in other formats, but for that you need to fork out money to get the Pro version. I then tried out iMovie, and managed to import the file as the sound track of a yet to complete movie. Attempts to extract the audio were fruitless; but then I accidentally noticed that the sound track was referred to as ‘aiff’ file. I opened the movie project package, and, hey presto, there was an aiff file. iMovie had converted it during the import.

So now I could import that into Audacity, and export from there to MP3.

Thinking Erlang, or Creating a Random Matrix without Loops 26 February 2009

Posted by Oliver Mason in erlang, misc, programming.

For a project, my Erlang implementation of a fast PFNET algorithm, I needed to find a way to create a random matrix of integers (for path weights), with the diagonal being filled with zeroes.  I was wondering how best to do that, and started off with two loops, an inner one for each row, and an outer one for the full set of rows.  Then the problem was how to tell the inner loop at what position the ‘0’ should be inserted.  I was thinking about passing a row-ID, when it suddenly clicked: lists:seq/2 was what I needed!  This method, which I previously thought was pretty useless, creates a list with a sequence of numbers (the range is specified in the two parameters).  For example,

1> lists:seq(1,4).
2> lists:seq(634,637).    
3> lists:seq(1000,1003).

Now I would simply generate a list with a number for each row, and then send the inner loop off to do its thing, filling the slot given by the sequence number with a zero, and others with a random value.

But now it gets even better.  Using a separate (tail-)recursive function for the inner loop didn’t quite seem right, so I thought a bit more about it and came to the conclusion that this is simply a mapping; mapping an integer to a list (a vector of numbers, one of which (given by the integer) is a zero).  So instead of using a function for filling the row, I call lists:seq again and then map the whole thing.  This is the final version I arrived at, and I’m sure it can still be improved upon using list comprehensions:

random_matrix(Size, MaxVal) ->
    fun(X) ->
          fun(Y) ->
              case Y of 
                 X -> 0; 
                 _ -> random:uniform(MaxVal)

This solution seems to be far more idiomatic, and I am beginning to think that I finally no longer think in an imperative way of loops, but more in the Erlang-way of list operations.  Initially this is hard to achieve, but with any luck it will become a lot easier once one is used to it.  Elegance, here I come!

Example run:

4> random_matrix(6,7).  

Note: I have used random:seed/0 above, as I am happy for the function to return identical matrices on subsequent runs with the same parameters. To get truly random results, that would have to be left out. However, for my benchmarking purposes it saved me having to save the matrix to a file and read it in, as I can easily generate a new copy of the same matrix I used before.

Dealing in meteorites 9 April 2008

Posted by Oliver Mason in misc.
add a comment

While clearing out a decade’s worth of paper from my office I came across an article in the Feb 2003 issue of the university’s in-house paper, Buzz. In one article, the following extract struck me: … artists had acquired a meteorite from a meteorite dealer in Scotland.

Several questions come to mind: Can you make a living as a meteorite dealer? I guess there are more meteorites hitting Earth as one would think, not all of course big enough to make (no pun intended) an impact. And why Scotland? Is Scotland especially prone to being hit by meteorites?

Thanks to the web, the first question can be supplemented by a useful snippet of information: Over the whole surface area of Earth, that translates to 18,000 to 84,000 meteorites bigger than 10 grams per year. But of course 70% of that end up in the sea, and most of them never make it through the atmosphere in the first place. I also don’t want to speculate how much demand there is for meteorites, other than from conceptual artists and perhaps astrophysicists.