Tuesday, May 31, 2011

Conversion of miles to kilometers (and back) using addition only

Some time ago I came across the trick that allows easy conversion of miles and kilometers (and also mph and km/h) using addition only. The trick uses the fact that the ratio of the Fibonacci numbers is very close to the conversion factor between miles and kilometers.

This is an example of turning multiplication to addition in a similar manner to the use of logarithms in a slide rule.

Firstly, the Fibonacci sequence is pretty easy to remember or regenerate from scratch because it is generated by the rule "the next number is the sum of the preceding two numbers". The sequence starts from 0 and 1 and then proceeds 1, 2, 3, 5, 8, 13, 21, 34, ... Each number is the sum of the previous two numbers.

Secondly, the ratio of consecutive Fibonacci numbers gets closer and closer to 1.62 the larger the numbers get. For example, 3/2 = 1.5, 8/5 = 1.6, 13/8 = 1.63, 21/13 = 1.62, 34/21 = 1.62, ...

Lastly, there are 1.61 kilometers in a mile. If you take the ratio of Fibonacci numbers as 1.62 then the error in using that for miles/kilometers conversions is about 0.5%. For everyday usage that's pretty good.

To go from kilometers (or kph) to miles (or mph) find the number in the list of Fibonacci numbers and look at the preceding number. For example, 34km (or kph) is 21.1 miles (or mph); using Fibonacci you get 21 miles (of mph). 8km is 4.97 miles; using Fibonacci it's 5 miles.

To go the other way (miles to kilometers) simply go the other way along the line. So find the number (in miles) in the Fibonacci sequence and get the kilometers from the next number.

On a recent trip to France I tried this out. The speed limit on a French autoroute is 130 kph which is 80.78 mph. Using the Fibonacci sequence it comes out at 80 mph (you can drop the 0 on both numbers since you're dealing with a ratio and go from 13 to 8 in the Fibonacci sequence).

When it's raining the speed limit drops to 110 kph. Now 11 doesn't appear in the sequence (again I've dropped the zero and will put it back in later). But 11 can be decomposed into 8 and 3 (11 = 8 + 3) and the answer obtained by looking at the mph figures for 11 and 3 in the Fibonacci sequence and adding them together. Thus we get 5 + 2 = 7 and so 110 kph is 70 mph (it's actually 68.35 mph). The error comes about because the early Fibonacci numbers are not quite at the right ratio. You can remove the error by remembering that 3 km is 1.8 (not 2) and then you get 5 + 1.8 = 6.8 (giving 68 mph).

Note that you can also use subtraction. For example, to work out 16 kilometers in miles you could look at 13 and 3 (to get 8 + 1.8 = 9.8) or you could do 21 and 5 (to get 13 - 3 = 10).

You can also play around with other tricks. For example, returning to 110 km you can see that it is 55 * 2 and 55 is a Fibonacci number. So at once you have 110km is 34 miles * 2 = 68 miles.

Wednesday, May 25, 2011

Playing Pong on a pair of candy cans: it's the Cansole!

A little while ago I mentioned that I was working on a new contraption: a video games console in a candy can.

It's now complete and I can play Pong on a TV. Here's a shot of the completed contraption. On the left is the main controller (the power switch is visible) and on the right is the expansion controller with its cable. The left (red) controller also has a 'fire' button that isn't visible and both have simple 'paddle' style controls.

On the bottom of the main controller are the main connections for the TV (video and audio) and a second controller.

The second controller contains nothing but a simple potentiometer.

But the main controller is much more complex. There's an Arduino Pro, a potentiometer (for the paddle control), a button for 'fire' or 'select', the battery and the connection to the video and audio and second controller. Video and audio are handled by the Arduino TVout library.

The entire thing is wired squashed bug style as it's mostly interconnections and only a few discrete components (three fixed resistors, and two potentiometers).

The device generates a PAL TV signal in software (that's the clever bit that TVout does). It can generate NTSC with no problem if the code is changed. Here's a quick shot on the oscilloscope of the PAL TV signal just showing that the sync pulse is coming every 64 us as expected.

And, finally, to test it out I wrote a simple implementation of the classic game Pong. The source code can be found here.

No such blog post would be complete without a video showing the Cansole and Pong in action.

PS A few people have asked for a schematic. Here it is.

Wednesday, May 18, 2011

The code on XIII : The Series

So, I watched an episode of the awful series XIII : The Series. In the first episode the main character comes across a memory chip in his watch and looks at it on a computer. He doesn't know what it is.

Here's a shot of what he saw:

Clearly, he's not a C programmer. I figured it would be interesting to track down the code that he was looking at. Using the function name 'tripcharup' I found this code.

The TV people seem to have extracted random lines from that file and repeated them over and over again on screen.

Monday, May 09, 2011

O Atlas Geek: 128 Lugares Onde a Ciência e a Tecnologia Ganham Vida (The Geek Atlas in Portuguese)

At the start of June, The Geek Atlas will be published in Portuguese by publisher Editora Altabooks (it's also available in German):
Os 128 locais abordados neste livro compõem uma lista pessoal de lugares para visitar onde a ciência, a matemática e a tecnologia aconteceram ou acontecem. Você não encontrará pequenos e tediosos museus de terceira categoria, ou placas presas à parede indicando que “o Professor X dormiu aqui” entre os locais selecionados. Cada lugar possui real interesse científico, matemático ou tecnológico.

Nem todos os lugares apresentam invenções ou descobertas humanas. Há também fenômenos naturais, como o variável Polo Norte Magnético e a Aurora Boreal. E há também alguns túmulos de cientistas famosos, mas tenha a certeza de que há equações neles.

Cada lugar tem seu próprio capítulo e cada capítulo é dividido em três partes: uma introdução geral sobre o local, com ênfase em sua importância científica, matemática ou tecnológica; um assunto técnico relacionado, abordado em maiores detalhes; e informações práticas sobre a visitação. O livro pode ser usado como um verdadeiro guia de viagens (e espero que você tenha a oportunidade de visitar alguns desses lugares), mas também pelo viajante de poltrona, a quem espero inspirar a deixar este livro de lado para aprender um pouco mais sobre a ciência, a matemática e a tecnologia aqui abordadas...

More details.

Next can-traption: Video Games Can-sole

So, to silence the people who keep asking "What are you going to do after GAGA-1?", here's the answer: I'm going to build a small video games console that fits inside a Marks and Spencer boiled sweet can. Here's a rough shot of the major parts:

That's an Arduino Pro, power switch, fire button, potentiometer, 9V battery, and two RCA connectors for composite video and audio.

Here's a shot of the can when it's closed. The potentiometer knob will be used to implement the games Pong and Breakout.

The video generation is going to be done entirely in software using Arduino TVout. Here's another shot showing the fire/select button.

On the back are the two RCA connectors for video and audio.

The tag for this project will be cansole.

Wednesday, May 04, 2011

OSCON '11 Keynote: Turing, Perl and Palpatine.

Last August I asked for your suggestions for a mystery keynote speaker slot, and got many good suggestions.

Finally, I'm able to say that the conference is OSCON 'll where I'll be giving a keynote on Wednesday, July 27, 2011.

The chosen subject is embargoed for the time being, but will feature a combination of Perl scripts, Alan Turing, and Emperor Palpatine. And we'll have some Arduino action and a dash of text mining as well.