Senior Mathematical Challenge

November 27th, 2007

A while back I posted about having taken part in the senior mathematical challenge. I recently got the result back and discovered that I have managed to get through to the second round which is the British Mathematical Olympiad.

It is on this coming Friday and will be three and a half hours long. It contains 6 questions for you to answer and from the past paper they gave me they look very hard. I don’t think I will be getting beyond this stage but it should be fun taking part. Despite the rather long length of the thing. I am not sure I will ever take a test that is this long again in my life.

Anyway it should be good fun and I will update when I get the results.

Computers in the Media

November 24th, 2007

Recently in the UK there has been a problem because somebody in the government has lost some discs which contain personal data about 25 million people including bank details in some cases. The BBC news had a report on this and one of the things that struck me most were the background pictures.

They had clearly tried to do a general computer theme but it was interesting what they had managed to find. There was binary code of course, a nice picture of a circuit board with some chips that had 8-16 pins on them, which are not used anywhere within the computing industry at all. They weren’t even surface mounted chips. There was some interesting xml code which was a bit messy, lacking in appropriate line breaks and indents and the tags were pretty unintelligible and finally they had a nice matrix style scrolling code clip, the falling green text with good quality motion blur effects.

This was just the background to the text information that they were showing and the speech but it did make me th9ink about how poorly computers are represented in the media. Films seem to be especially bad, even when this is central to the film such as in swordfish, which is a film about a computer hacker.

Swordfish will give the unsuspecting viewer an interesting view of the way that hackers work and the limitations of what they can do. The hacker doesn’t seem to like compiling his code, since in the first part that they show him working he is told to crack some American high security thing in a minute and he just seems to keep typing constantly. I got the impression that he was just executing the commands as he went along.

Another interesting thing was that he was told to try and hack into a computer from the login screen. Unless a flaw had been specially designed to make it hackable it shouldn’t be too difficult to secure a login screen so that people would have to tamper with hardware to get it to work. This will lead people to believe that hackers can crack things which are just not possible.

Finally and probably the most blatant thing is the worm that the hacker creates. The worm is interesting because he seems to have programmed a cool 3D interface which shows some cubes sliding around as the worm tries to get the right configuration. He actually uses this on a bank computer, now I wonder what would have happened if the computer hadn’t had 3D graphics support? Nobody programs a 3D user interface for a worm. There just isn’t any point whatsoever.

I don’t really know what effect this has on the public but I would imagine that it would have some effect of influencing them.

Firefox 3 Beta 1

November 20th, 2007

I use firefox as my primary browser so I am naturally fairly interested in the development of firefox 3. I have installed a few of the alpha releases but now the firefox 3 beta has been released for download. There is a feature list on the mozilla website so I don’t really see the point in elaborating on that since theirs will be more complete.

The thing that I probably find most annoying about firefox currently is how the ram usage slowly creeps up, my PC is about 6 years old now and has 768mb of ram installed (I upgraded). This means speed is a fairly big issue currently. The beta seems to run pretty quickly and I was pleased to see the ram usage kept pretty low. There is a test page that I use which has a lot of css on it and that quickly moved the ram usage for about 50 - 120. When I then closed the tab I noticed that it only took a few seconds before the ram usage had dropped right down to the original.

There seems to be a bit of a bug with the canvas object because when I tried running my physics engine it messed up drawing the circles. Just squares were fine, and I am sure it was the drawing part that was going wrong because when I just changed the code that just drew the shape so it drew a square instead it worked fine. I submitted this to bugzilla and discovered that it was a fault in my code due to the canvas code that draws and fills the circle in firefox 3 being implemented slightly differently to firefox 2. It turned out that my code never finished drawing the arc (a 360 degree arc made the circle) so it ended up trying to draw hundreds of the arcs each frame which was why it got intolerably slow. The bug is now fixed.

Also firefox didn’t like being closed. It put my cpu at 100% for about one and a half minutes before the process actually ended. Hopefully this will get fixed since it is only beta 1.

Some of the features do look quite nice. I especially like the feature to pause downloads and then resume them even after you have closed the browser. Also the upgraded plugin manager is nice.

The best way to find out about it is to go and download the beta now and try it yourself.

Javascript Physics Engine

November 19th, 2007

This is my latest javascript project, using the canvas object. I have posted about making a 2D and 3D lindenmayer system earlier on. I don’t really like the flash platform mainly because you have to pay for flash and I also don’t really like the way the movie clips are handled in the script from when I have used it as my school. This means that javascript is the only other option really for anything web based (Microsoft silverlight isn’t popular enough currently).

I found that some people have used native features of internet explorer to create a canvas object that works in internet explorer. Unfortunately this is terribly slow currently but there is nothing which can be done about that. This means that my example script does with with internet explorer and amazingly no modifications were needed other than including the explorer canvas script.

At the moment my physics engine is woefully incomplete. At the moment there is no collision detection other than with the floor and both walls. I am going to be working on the collision detection next since it is a pretty major part. I am still playing around with different algorithms currently, looking for a high speed routine. The system for adding dynamic and static objects to the world works well enough for now but I will expand this as features are needed. I haven’t put any static features in the demo because they are not very exciting since they just stay there and don’t even collide with things. Gravity is implemented.

I have only put in a small number of objects because I felt sorry for the people with internet explorer. Hopefully the final release will be feasible for IE because there shouldn’t be too many dynamic objects to be drawn and I should be able to get a pre-rendered scene for the static objects. The rest is done in plain javascript which doesn’t take a big performance hit.

First physics engine example.

Mandelbrot Set

November 17th, 2007

The Mandelbrot set is an interesting mathematical concept because it is so amazingly simple yet it leads to such astonishingly complex results. I thought it would be interesting to have a go at making my own Mandelbrot set generator. I chose php because I was also interested in looking at optimisation techniques and a Mandelbrot set generator definitely needs all of the optimisations it can get.

Having made the program I have now realised that php is just not cut out for doing stuff like this so it would be a better idea to make it in something like c++ so that I could add more features like being able to smoothly zoom into the picture perhaps, or at least cut down the 25 second rendering time for a 500×500 picture.

First, since the Mandelbrot set uses complex numbers, I logically looked towards procuring a complex number class for php. I found a class pretty quickly but fortunately (yes it isn’t a typo) it wasn’t documented. This meant that I didn’t feel the urge to thoroughly scan the code to work out how to use the thing so I gave up on it saving myself time and bother. Later on in the script when I was optimising I realised that classes are a lot slower than normal variables, I think it would have been over 4 times slower at the lower estimate.

For those of you who don’t know the formula for the Mandelbrot set is z -> z^2 + c. Where z is a complex number which starts as 0 + 0i and c is the point of the complex plane that you are looking at. The formula is repeated large numbers of times and in my program I allowed this value to be changed. If z goes off to infinity (as soon as |z| > 2 you know it will just keep increasing) then the point is coloured white otherwise it is coloured black.

You will now look at my program or many other Mandelbrot set pictures and point out that they are all in pretty colours. The reason for this is that we programmers like pretty pictures, since the Mandelbrot set programs don’t produce anything else, so we look at how many iterations it takes until |z| > 2 and then work out a colour based on this value. My program works in the range from bright yellow to red since I was too lazy to program in a whole spectrum gradient but many other programs will use the full spectrum or something even more exotic.

There isn’t really much more to it than that and the program is pretty short. My PC takes about 25 seconds to render the 500×500 with 100 iterations and I have a p4 3.2 Ghz so everybody should be able to have a go at rendering it if they want to and they have php installed. I haven’t put the php script on my website because I want to keep on good terms with my host and I don’t think locking up the cpu for about 20 seconds will please them.

To use the script put it on your server (preferably on your own PC) and then open the web page. If you want to change the things you are looking at just adjust the constants and variables at the top of the script. They are pretty self explanatory. The iteration number will probably need to be increased if you decide to zoom in but when you aren’t zoomed in it should be kept low to speed things up.

The Code

An image generated my my mandelbrot set.

Installing Eclipse on Windows

November 14th, 2007

I am writing this post because when I had a go at installing the eclipse development platform I had a bit of trouble getting it installed and working. I would imagine that most people wouldn’t encounter this problem but I had real trouble finding any information on it so I thought I would post the fix.

To install eclipse you first download the zip from their website and extract it to wherever you want the program to be stored. There is no installer so you will want to create shortcuts etc. yourself. This can be easily done by right clicking and selecting the new shortcut option.

When I had unzipped I tried running the Eclipse.exe file however it produced an error saying

“A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available to run Eclipse. No Java virtual machine was found after searching the following locations:
location_of_script\jre\bin\javaw.exe”

This was surprising because I have a working installation of Sun Java that has been picked up by every other Java program that I have ever tried to run. Searching the internet didn’t turn up any obvious fixes however after a bit of searching I found out that there is a command line parameter that you can set to specify the location of your JRE.

So to fix this error you must first find you JRE. Mine was fairly easy to find, just by browsing the program files folder and looking in the Java folder and then the bin folder within that. If you have trouble then just run a search for “java.exe” and it should find it. Write down or copy the path of the java.exe file making sure oyu include \java.exe.

Now go back to the location of your eclipse installation and create a new shortcut to eclipse.exe (right click -> create shortcut). Now right click your shortcut and go to properties. In the target box go right ot the end of the string and then type:

-vm “MyJavaPath”

Where MyJavaPath is the path to your java.exe. So for example target ended up looking like this:

“C:\Documents and Settings\MyUsername\Desktop\eclipse-java- europa-fall2-win32\eclipse\eclipse.exe” -vm “C:\Program Files\ Java\jdk1.5.0_07\bin\java.exe”

Now you should be able to launch eclipse by running this shortcut. I have yet to find a way to get eclipse to remember where your java.exe is so you will have to use the shortcut to launch it for now.

I hope this helps some people who are having problems.

Google Android

November 14th, 2007

Google Android is a new mobile phone software development kit that has been created by the Open Handset Alliance and is prominently supported by Google. The SDK has just been released for developers and it uses the Java programming language. The applications are compiled before being loaded onto the device. There is a virtual machine provided with the SDK to allow for testing the software.

There have been mixed reactions to the announcement from various people. Notably a spokesperson from Symbian, a company whose platform powers millions of mobile phones, said “It’s very clear what developers want - volume and a stable platform that doesn’t keep breaking. You have to have a lot of zeroes in your sales figures before a developer gets out of bed.” This may indeed be what the professional developers employed by many large companies want however Google looks to be targeting a different sort of developer.

Google has launched the Android Developer Challenge which has $10 million worth of prize money for applications for Android. This is clearly meant to entice large numbers of developers to take part and I would think that many of them will be interested in the open source movement. You could argue that most of the applications submitted will be of a fairly poor quality, produced by amateurs who don’t really know how to design and polish an application, there will undoubtedly be a lot of these kind of applications. However I would imagine that there will also be a large number of high quality applications produced, partly just because the scope for developing for a mobile device is far more limited compared to a PC.

The screen area is very small as well as the processing power so large complex menus and interfaces just aren’t possible, the simplicity of the applications works in the favour of small scale developers. Also I have looked at the developers kit and there is a good framework and API set there to work with. The system encourages use of mashups as they are called where the developer takes several existing elements and combines them in a unique and useful way.

If you are a developer I would recommend taking a look at the SDK since it is fairly interesting and if you are anything like me new cool things are exciting. Even if you are not a developer you might be interested in just looking at the platform in the emulator although I guess it is quite a lot of bother with all of the downloading.

http://code.google.com/android/

FreeRice Vocabulary Game

November 12th, 2007

A friend recently told me about a game called FreeRice. Basically they ask you for the definition of a word and for every word that you answer correctly 10 grains of rice are sent to help stop world hunger. As you get more words correct the difficulty level increases. The game gives you a vocab level so you can keep track and compare yourself to your friends. I ended up with a vocabulary level staying around 35/36, although with my parents helping we managed to get up to about 45 peaking at 47. The score is out of 50. The game checks how hard words are by looking at how many people have previously answered them correctly, this is similar to the 20Q method.

Since the site only tells you about the number of grains of rice I decided to investigate further and look at what the rice was worth in terms of how many people it could feed. Luckily I had access to Wikipedia which could provide all of the information that I needed.

Wikipedia already has a dedicated page on rice which helpfully tells us that 10000 grains are needed per person per day so that is 1000 correctly answered questions. That does seems like an awful lot of questions so this is clearly not the most efficient way to stop world hunger, a better method would be to get a part time job and just donate the money earned.

But that said, it is a fun game to play and of course it does help quite a bit if loads of people play it. There was story I heard about a man who walked along a beach where there were thousands of starfish washed up on the sand after a storm and he came across another man who was throwing some back into the sea. The first man asked the second why he bothered because he was hardly making any difference. The second man replied that it made a difference to the one that he threw back into the sea.

So although it may not seem significant on the large scale of the many millions who are near starvation but it does make a difference to somebody.

http://www.freerice.com/index.php

Senior Mathematical Challenge

November 9th, 2007

Yesterday I took part in the Senior Mathematical challenge. This is a test that is created by the UKMT (United Kingdom Mathematical Trust) which is designed to test your mathematical skills more than your actual knowledge. The paper lasts 90 minutes and is multiple choice. Unlike most exams if you get questions wrong you lose a mark however you gain 4 marks for every question you answer correctly. Since there are 5 choices per question you are likely to end up with negative marks for randomly answering questions. This is so that people work them out rather than randomly guessing at the end.

The UKMT have a website which has a few past papers on it including the one that I did. I will post again when I find out my result. I have done the tests in three previous years, Twice with the junior and once with the intermediate. I have done 2 junior second rounds and 1 intermediate so perhaps I might get through again, but I am not sure because it is meant to be quite a bit harder. The paper is 3 1/2 hours long for the second round though.

3D Lindenmayer Systems with Javascript

November 2nd, 2007

Just cloning the Lindenmayer script which I found seemed a bit simple and a bit like I was copying them. So I decided that I would use my knowledge of 3D programming which I picked up in VB (you can see the tutorials on the main site) and make a 3D version of the Lindenmayer System. The 3D code is basically a direct port from my 3D VB code which used matrices to perform the transformations.

I have put this script on a separate page because to rotate and move the object so you can get a better look the keyboard is used so people scrolling with the arrow keys or trying to type a comment could encounter problems.

Here is the link 3D Lindenmayer system.

See my previous post for more Lindenmayer system stuff.