Project Euler: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 14: | Line 14: | ||
==Problem 2== | ==Problem 2== | ||
<code> | <code> | ||
i=1 | i=1 | ||
j=1 | j=1 | ||
y=[] | y=[] | ||
while True: | while True: | ||
k=i+j | |||
if k>4e6:break | |||
i=j | |||
j=k | |||
if k%2==0:y.append(k) | |||
print sum(y) | print sum(y) | ||
</code> | </code> | ||
==Problem 3== | ==Problem 3== | ||
==Problem 4== | ==Problem 4== | ||
==Problem 5== | ==Problem 5== |
Revision as of 07:09, 7 August 2014
Problem 1
x=[]
for i in range(1000):
if i%3==0 or i%5==0:
x.append(i)
x=np.array(x) #turns list into numpy array
y=np.sum(x)
print y
Problem 2
i=1
j=1
y=[]
while True:
k=i+j
if k>4e6:break
i=j
j=k
if k%2==0:y.append(k)
print sum(y)