It was refreshing to have a problem that I could do in just one try. The ones I’ve been working on recently have been really tough! This one took some thought, along with some calculations on paper to figure out the right sequencing.
def seq(n):
if (n-2)%3 == 0:
return float(2*(1 + ((n-2)/3)))
else:
return float(1)
def e(n):
if n == 1:
return 2
else:
frac = [float(0), float(1)]
for k in range(n-1, 0, -1):
frac = [frac[1], frac[1]*seq(k) + frac[0]]
return [2*frac[1] + frac[0], frac[1]]
e_string = str(int(e(100)[0]))
total = 0
for i in e_string:
i = int(i)
total += i
print total