Project Euler: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[https://projecteuler.net/problems;page=1 Project Euler] | [https://projecteuler.net/problems;page=1 Project Euler] | ||
==Problem 1 | ==Problem 1== | ||
< | <syntaxhighlight lang="python"> | ||
x=[] | x=[] | ||
for i in range(1000): | for i in range(1000): | ||
Line 10: | Line 10: | ||
y=np.sum(x) | y=np.sum(x) | ||
print y | print y | ||
</ | </syntaxhighlight> | ||
==Problem 2== | |||
<syntaxhighlight lang="python"> | |||
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) | |||
</syntaxhighlight> | |||
==Problem 3== | |||
<!---syntaxhighlight lang="python"> | |||
</syntaxhighlight---> | |||
==Problem 4== | |||
==Problem 5== |
Latest revision as of 18:19, 7 August 2014
Problem 1
<syntaxhighlight lang="python">
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
</syntaxhighlight>
Problem 2
<syntaxhighlight lang="python">
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)
</syntaxhighlight>