After a 6 month break, I’m back at project Euler again.
One of the new problems: continued fraction calculation, I find it really odd that there’s no a lot of good source on a step by step algorithm to calculate it. So I’m just going to write it here, in python.
#calculate the sqrt of a number as a series of continued fraction co-efficient
num = 22
sqrt = Decimal(num).sqrt()
if math.ceil(sqrt) != math.floor(sqrt) : #wish I know a better way to check this
while count < 100 : # wirte out the first 100
count = count + 1
sqrt = Decimal(1) / (sqrt - Decimal(math.floor(sqrt)));
print (sqrt)
Also learning python, which is pretty fun.