ProjectEuler_2
来源:互联网 发布:js实现网页中英文切换 编辑:程序博客网 时间:2024/06/03 18:09
i=2_sum=0a={0:1,1:2} #you cannot give value to a index that not exist in Listwhile True: a[i]=a[i-1]+a[i-2] if a[i]>4000000: #break condition break if (i%3==1): #only this item is even-valued _sum+=a[i] i+=1 print _sum+2
这代码龊的一比啊,这是在写C语言吧,靠。弄了两个pythonic的代码来学习下。
s = 0a, b = 1, 1while a < 4000000: a, b = b, a+b if a%2 == 0: s += aprint s
a = [1,2]i = 2while a[-1] < 4000000: a.append(a[i-2] + a[i-1]) i += 1print sum(filter(lambda x: x%2 == 0, a))
这两段都是阿三哥写的,转自PE的论坛,hk97和hkapur97。
- ProjectEuler_2
- ProjectEuler_2
- 面试题解析之代码的健壮性
- c++学习小结
- 怎样以少于1000行代码写一个视频播放器-引言
- uva10034 - Freckles
- Hdu 1062 - Text Reverse
- ProjectEuler_2
- 网络安全书籍介绍
- HDOJ2015 偶数求和
- 创建MySQL数据库中useUnicode=true&characterEncoding=UTF-8
- StringBuilder与StringBuffer知多少
- 查找ruby方法(以rails为例)
- 深入linux网络编程(一):同步IO
- MongoDB核心贡献者:不是MongoDB不行,而是你不懂!
- 深入linux网络编程(二):异步阻塞IO —— select