Created 14th January, 2010 05:03 (UTC), last edited 14th January, 2010 05:03 (UTC)

Miles to kilometres Fibonacci style

*After a short hiatus due to Christmas and new year — *Happy New Year* — the puzzles are back*

There are 1609 meters to a mile and the Golden Ratio is about 1.618. This is just close enough to be able to use consecutive numbers in the Fibonacci sequence to convert between miles and kilometres. It works because consecutive numbers in the Fibonacci sequence approximate the Golden Ratio.

**Write a program that converts from miles to kilometres (and back again) using the Fibonacci sequence where the numbers to convert are in the sequence**

I.e., if 5 is input this is the equivalent of 8 kilometres if the 5 is taken as miles and is equivalent to around 3 miles if the 5 is taken as kilometres.

If we have to convert a number that isn't part of the sequence then we will need to find numbers in the sequence that add up to the number we want to convert.

**Change the program so that it can convert numbers that are not in the sequence**

I.e. for 100 we would want to find numbers in the Fibonacci sequence that add up to 100, convert them and then add up the results. So, 100 = 89 + 8 + 3:

- 89 is 55 miles and 144km.
- 8 is 5 miles and 13km.
- 3 is 2 miles and 5km.

This means that 100 is 55 + 5 + 2 = 62 miles and 144 + 13 + 5 = 162km.

**Add in the real conversions using one mile as 1,609.344 metres and display the error alongside the results**

100 is actually 62.137… miles so the error is about 0.2%. 100 is also 160.9344 km so the error in the other direction is about 0.7%.

Categories: BeerCamp puzzle

© 2002-2019 Kirit & Tai Sælensminde. All forum posts are copyright their respective authors.

Licensed under a Creative Commons License. Non-commercial use is fine so long as you provide attribution.

kirit.com