Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 28 lines (22 sloc) 0.638 kb
affdcbe @coleifer Solved 65
authored
1 # e can be expressed as a continued fraction of the form
2 # [2;1,2,1,1,4,1,...1,2k,1,...]
3
4 def get_nums(amount):
5 i = 1
6 nums = [2]
7 while len(nums) < amount:
8 nums.extend([1, 2 * i, 1])
9 i += 1
10 return nums[:amount]
11
12 nums_to_calculate = 100
13 a = 2
14 nums = get_nums(nums_to_calculate)
15
16 numerator = 1
17 denominator = nums[nums_to_calculate - 1]
18
19 for i in xrange(nums_to_calculate, 1, -1):
20 prev_num = nums[i - 2]
21 if denominator != 1:
22 prev_num *= denominator
23 combined_num = prev_num + numerator
24 numerator = denominator
25 denominator = combined_num
26
27 print sum(int(d) for d in str(combined_num))
Something went wrong with that request. Please try again.