Tag Archives: convergent

Euler Problem 197 – Convergent Functions

I solved this one kind of by accident. Its a short program (most things in Haskell are) and I coded it in just a few minutes. Then I plugged in a starting series of 10^6 numbers. Thought that would be a good start. Got the result in a few seconds, and figured that I would need to do the full 10^9 digits. Left it to work over the weekend. Of course, it never finished.

After analysing the function a little more, I discovered that its an oscillating convergent function. Interestingly, after only a few thousand numbers, the varience is smaller than 10^-9. So by using 10^6, it was already overkill.

f :: Double -> Double
f x = 
	let a = 30.403243784-(x**2)
	in fromIntegral (floor (2**a)) * 10**(-9)

u :: Double -> Double
u 0 = -1
u n = f ( u (n-1)) 

main =
	let n = 10^6
	in print $ (u n) + u(n+1)