## 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

### ASCII Art Stephen Fry

```      I\$DZDOND8I87Z\$DO8DD8D88NDDDD\$DO8DNDDD,?:+..                              M
.ZOODD8DZDZO7OOO8O878OZO7\$OZDZ8NNNNDNNDOOD?.:                              M
?ODIDDO8887ZOOZZ8OZII7ZIZOOZ8D8Z8NNNN8D8D8888I                              M
788DDD88ODDOD\$ZO88\$OOZ77?ZZZ\$\$ODZ88N8\$NDDNONDDOO,                            M
.I?88DNODDDDOOZZOZO8OOOOOOODDO888\$ZO8DDD8ODD8D88Z887                           M
~?DD88NDDD88DOD8O8OO8OZ8\$\$\$\$ZZ8OD888ODZD8D8NND8\$DZDOO                          M
=:8O8NDNDDNN\$DDD8O8O8O8O8ZZOD88ZDI88888ODD8D88DZO8D888?.                       M
+IONNDDDNNDOODNDND8O8\$7ZIZZOOO88ZO8O\$Z88DOOO8D87ZOOOO7O?                       M
~8DD8DNNNN8DNNDD88O8\$\$ZZ\$7?77IZ\$ZOOO8O88O8ZOZ8Z\$7??OO=?7I                      M
7DNNNNNNNDDNNNDDOO8888OOZ\$Z77I\$7\$\$Z7Z\$77\$\$I?=I?\$++7Z88\$Z::                     M
ODDNNNNDDNNDD8D88888OOZI\$7I77I?II7\$7I\$7I=?~=?+7?\$ZII878\$:+I                    M
8DNDNNNN88DDDD88O88Z\$Z\$II7I7?=I?+?7I?=~:::::~~\$I\$IZ\$O8\$O??=                    M
DNDNDDNNN8DD888OOZ8Z\$77\$\$++=~=+===+=:::,,,,::=?I+\$88IO7OO=.                    M
DDNDNNNDD8DDDDOOZ\$7\$\$I\$I+++~~~:::,:.,...,,,,:~+I\$OO8OZOO8II                    M
D8NNNND8DND8OZ\$O\$I7??7+=~:~::~,.......,..,.~::+7IOZZN\$ZZ8D,                    M
8DNNNNNDD88OZZO7???+I=~:::,,.,,.,.......,,,,::=+?ZZ7\$8D8\$O .                   M
NDDDNNODD88OZ\$77?++=~~:::,,,............,,,,,:==+O8ZZZOOO87                    M
88NDDD8DDDOOZZI?I+~::,,.,,....... .......,,,::~~+ODOODD88Z.                    M
NN8N8DDD8OOZ\$7???=~::::......... . ........,,,:~+Z8OO8DIZI                     M
NDD8DD8888Z\$777II+~::,,.,........,.... .....,::~~?ZZ888O7=                     M
DNDNNNN88OZI\$ZZD8DZI=:,:,,,,,,,,,,,,,,:.,,.,,,:~~~77ZOIZ+                      M
8DNDDD888OZ88DOOZO88O\$?=:::,::::==I+I7777I:~=::~~:\$ZZO\$=,                      M
ODDDDN8O88DO\$I?=:,,:+ZO\$7I~:,:~~?+I7=~:,,:,=?+?~~:~D\$8+=                       M
,D88NN8OO8DO\$7\$DD88O\$\$+IOZ~,,.,=?+~~=?+:.,,,~~?~::~7?7?~                       M
DI7D8OO8Z88DDD\$\$7\$,,+I=?Z~,..,:7I77I+ZN8O8=~~?~,~=77Z?:                       M
,OZO8D88OO8D8O\$?:~:~:~~:?7:,..,,,,==~,:,,~:?O?::::=\$?I=~                       M
Z?ZOD8OZI77OOZ7I??I+:,++7=,..,,..:II+~~~~~~:,,,:~=\$Z~:                        M
8?OD8DZ\$I+I77??+===~+??7+,.,,,,,.,~==II+=::,,.,~++?:,                        M
8ZODD8OZ7?====~=~===?7II?:,.,,.,,,.....,,.,,,,::7=:.:                        M
O8Z8DD8Z\$7?~:::::~~+I7\$7?=,..,,,,.... . ...,,::~ZI:~.                        M
88O888Z\$I?=~:::,:~+\$OO\$?+:,..,:~,.,,.,....,,:~~+::,                         M
.8D88OO\$7I=~::::~+ZO??\$I=~,..,,,I=:,:,,,,,,:~~=,,,:                         M
:888OOZ\$I?~~~~=?77O7???+:,..,,,:7I~:,,,,,,:~~=,,:                          M
8O888Z\$I?+=+?I?I88O\$7=~::,,~~=:?7+~~::::=~~~::                           M
OO888OZ77III?7\$ODNN8ZI?++?\$~,,:+\$I+===++==.                             M
\$O88888OZ\$ZI7\$7\$ODDDDDDZ7+~:,:~=?Z7II=+++=                              M
OOOZ\$7?II?II\$\$\$ZZZO\$Z\$7?=:~~::,,=?I+~====                              M
7OOZ\$?+~?\$7ZZZ\$\$\$\$7+?+==~~===+?=~~~~=~~=:                              M
OZ\$Z7+~~?+?I\$O888OZ7I7II??IZ++~=::=~~=~.                              M
ZO\$\$7?+=+==+??7I?=~~~=:~+=:,,,::::~:~+=~                              M
O8Z\$Z7?=++~++I??+=~~~~,:~:,,,,::==~~=+I7.                             M
ZD8OZZ\$II?+==+I7II~??+I~=::,,,,~~+~~=+?8Z.                             M
+ONN8ZZZ\$I+==~=+++?++++=I~~,,.:::~==~=I+O8..                            M
78NND8OOO7?==~:~:::~::::,,,,:,::~===+II+Z\$.,,.                          M
\$7ZONNNDD88O7+==,:~::,,,...,,,,,:~=+??I7?+\$=.,,,8~                        M
+NDZZZNNNDDDDD\$+=~?:::,,,.,,,..,::~=++?\$I?+7Z,.::.8D8888                    M
+DDNNDOOZ8NNNDNND8II+=~~~~::,.,,.:,:~?I+\$\$???+\$Z.:~:.DDDDDDD88Z                M
NNNNNNO8OZNNNNNDND8\$I?++==~:::~::~~~+77Z\$?+++=Z,.:~:,DDDDDDDDDD88?             M
NNNNNN8D878NNNNDNDNDOOZII??++====~=7\$ZZ\$?+++=I~.,:::8DDDDDDDDDDDD88O           M
NNNNNN88D\$\$8NNNNDDDDNDD8OOOZ\$7\$I7ZOOOZI?+=~=?=..==::NDDNDDDDDDDDDDDD88.        M
NNMNMNN8D8?78NNDNNDNDDNNDDDDDDD88OO\$I?+~=~=+~..,=:,DNNDDDDNDDDDDDDDDDDDOZ      M
NNNNNMNO8D??78NNDNDNDDDDDDDD8OOOZ\$\$I?=====+=,..==,DNNDNNDNNDDDDNDDDDDDDDD8O?   M
NMNMNMMMODD+IZ\$NNNNDDDDDDDD8OZ\$\$\$I?++~=+~+:, :++.DNNNNNNNNNNDDDDDDDDDDDDDDD88OIM
NNNNNMMMN8D\$ON87NNDDDDDDDD88OZ\$\$\$7I+++==+~7,.~=,8NDDNNDNDNNNNDNDDDDDDDDDDDDDDD8M
NNNNMMMMM8DD7ON8O7D8888OO88OZ\$777I?+~==,=8DO=:,DNNDNNNDNNDDDNNNDNDDDDDDDDDDDDDDM
NNNNNMMNNM8DDI8DDO?=OZ\$\$\$\$ZZ\$I?II~~: ,7\$O8Z+=,ONNNDNNNNDNDNNDNDDDNDDDDDDDDDDDDDM
NMNMNMNMMMMODDOODD8DZI:??I7\$\$77+Z8Z\$I++I\$?+..DDNNDNNNNDNDNNNNNDDDDDDDNNDDNNDDDDM
NNNNNMMMNNMM\$88OZ888OO8+=+?III:=++==++?II:,.DNNDNNNNNDNNNNNNNNDNDNDDNDNNDDDDDDDM
NNNNNNNNNNMMN=I7Z??IZO7?====?~.,:~=:,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NNMNNNNNNNNNNMNNNNNNNNNNNNNNNNNNNNNNNNNNM
NMMNMNNMNNNNNNMNMNMNNNNNNNNNMNNNMNNMNNNMNNNNNNNNMNNNNNNNNNDNNNNNNNNNNNNNNNNNNNNM
NMNMNNNNNNNNMNMDMDMNNNDNNNNMNNNNMNNNNNNNNNNNMNNNNMNNDNNDNNMNNNNMNNNNNNNNNNNNNNNM
NMNNNNNNNNNNMNMNNMNMNNMNMNNNNNMDMNNDNNNNNNNDNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNM
MNNMMNNNNNNNNNMMNNNNMNNNNNNNNMMNNNNNMNNNMNNNMNNMNNNNNNNNNNMNNNNNNNNNNNNNNNNNNNNM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
```

### 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.