[)roi(]
Executive Member
- Joined
- Apr 15, 2005
- Messages
- 6,282
Conversions between imperial and metric has never been easy to remember.
For example:
To test that theory I wrote some Swift code to convert miles to kilometres, using the fibonacci sequence as the input for miles:
Here's the result, the equivalent km values have been rounded up to the nearest integer value.
Surprising isn't it.
Note:
The above calculation loses a bit of precision after the 10 values, but it's accuracy it still fairly good, e.g. 40th fibonnaci number is 433494437 (miles) vs 431165193 (km). The loss of precision is definitely down to the use of 1.60934 -- if I use 1.6180339887 then the precision tracks perfectly through to 40th fibonacci number.
Makes me wonder if there is some back story to this relationship, and whether the correct multiple should be based on the ratio between fibonacci numbers i.e. and not the 1.60934 Google suggests?
For example:
- According to Google; To convert miles to kilometres, we have to multiply by 1.60934 (yip, not so easy to remember)
To test that theory I wrote some Swift code to convert miles to kilometres, using the fibonacci sequence as the input for miles:
Code:
import Foundation
struct Fibonacci: IteratorProtocol
{
var previous: Int = 1
var value: Int = 2
mutating func next() -> Int?
{
(self.value, self.previous) = (self.value + previous, self.value)
return value
}
}
let line = String(repeating: Character("-"), count: 19)
let title = String(format: "| %@ | %@ |", "miles ", " km ")
var fibonacci = Fibonacci()
print("\(line)\n\(title)\n\(line)")
for i in 1...10
{
let miles = fibonacci.next() ?? 0
let km = Int(round(Double(miles) * 1.60934))
let text = String(format: "| %6d | %6d |", miles, km)
print(text)
}
print(line)
Code:
-------------------
| miles | km |
-------------------
| 3 | 5 |
| 5 | 8 |
| 8 | 13 |
| 13 | 21 |
| 21 | 34 |
| 34 | 55 |
| 55 | 89 |
| 89 | 143 |
| 144 | 232 |
| 233 | 375 |
-------------------
Note:
The above calculation loses a bit of precision after the 10 values, but it's accuracy it still fairly good, e.g. 40th fibonnaci number is 433494437 (miles) vs 431165193 (km). The loss of precision is definitely down to the use of 1.60934 -- if I use 1.6180339887 then the precision tracks perfectly through to 40th fibonacci number.
Code:
---------------------------
| miles | km |
---------------------------
| 3 | 5 |
| 5 | 8 |
| 8 | 13 |
| 13 | 21 |
| 21 | 34 |
| 34 | 55 |
| 55 | 89 |
| 89 | 144 |
| 144 | 233 |
| 233 | 377 |
| 377 | 610 |
| 610 | 987 |
| 987 | 1597 |
| 1597 | 2584 |
| 2584 | 4181 |
| 4181 | 6765 |
| 6765 | 10946 |
| 10946 | 17711 |
| 17711 | 28657 |
| 28657 | 46368 |
| 46368 | 75025 |
| 75025 | 121393 |
| 121393 | 196418 |
| 196418 | 317811 |
| 317811 | 514229 |
| 514229 | 832040 |
| 832040 | 1346269 |
| 1346269 | 2178309 |
| 2178309 | 3524578 |
| 3524578 | 5702887 |
| 5702887 | 9227465 |
| 9227465 | 14930352 |
| 14930352 | 24157817 |
| 24157817 | 39088169 |
| 39088169 | 63245986 |
| 63245986 | 102334155 |
| 102334155 | 165580141 |
| 165580141 | 267914296 |
| 267914296 | 433494437 |
| 433494437 | 701408733 |
---------------------------
Makes me wonder if there is some back story to this relationship, and whether the correct multiple should be based on the ratio between fibonacci numbers i.e. and not the 1.60934 Google suggests?
Last edited: