摘要: 为什么 (R1*R2)/(R1 + R2) 与 1/(1/R1+1/R2)求得的值不同。(define (par1 r1 r2) (div-interval (mul-interval r1 r2) (add-interval r1 r2)))(define (par1 r1 r2) (let ((one (make-interval 1 1))) (div-interval one (add-interval (div-interval one r1) ... 阅读全文
posted @ 2011-10-24 21:21 class 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 无聊的蛋疼。#!/usr/bin/env pythondef Hanoi(n): #递归解法 def han(A,B,C,n): if n==1: print n,A,"-->",C else: han(A,C,B,n-1) print n,A,"-->",C han(B,A,C,n-1) han('A','B','C',n)def Hanoi(n): #非递归解法 even=('A','B','C') odd=('A',' 阅读全文
posted @ 2011-08-05 18:18 class 阅读(456) 评论(0) 推荐(1) 编辑
摘要: Problem: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million.问题: 小于10的所有素数的和为 17。求小与2,000,000的所有素数的和。方法: 筛法求素数。View Code def primes(n): if n<2: raise StopIteration else: yield 2 l=[True for i in range((n-1)//2)] for i in range(len(l)): if l[i]: y 阅读全文
posted @ 2011-06-07 10:01 class 阅读(421) 评论(0) 推荐(0) 编辑
摘要: 使用动态规划来求解问题使用10*101的数组,l[i][j]表示随机i个的数,总和为j的所有可能性的数目。那么l[i][j]=sum(l[i-1][k] for k in range(j-50,j+1) if k>=0)使用1 到 l[i][j]中的每一个数字表示一种方案,将 1到l[i][j] 分为 50个区间1 到 l[i][j-50] ,1+l[i][j-50] 到 l[i][j-50]+l[i][j-49],1+l[i][j-50]+l[i][j-49]到 l[i][j-50]+l[i][j-49]+l[i][j-48]随机出 1到l[10][100] 之间的数字,然后构造出一种 阅读全文
posted @ 2011-06-01 11:38 class 阅读(1030) 评论(1) 推荐(0) 编辑
摘要: Problem 9: A Pythagorean triplet is a set of three natural numbers,abc, for which, a2+b2=c2 For example, 32+ 42= 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for whicha+b+c= 1000. Find the productabc.问题9: 寻找和为1000的毕达哥拉斯三元数(勾股数)。思路: a2+b2=c2<a2+2ab+b2=(a+b)2 c<a+b,a+b+c=1000, 阅读全文
posted @ 2011-05-31 09:45 class 阅读(324) 评论(0) 推荐(0) 编辑
摘要: Problem 8: Find the greatest product of five consecutive digits in the 1000-digit number.问题: 找出1000个数字中连续5个数乘积的最大值方法一: 由题意直接写代码:View Code from functools import reducefrom operator import muldef f1(s): l=list(map(int,''.join(s.split('\n')))) return max(reduce(mul,l[i-4:i+1]) for i in 阅读全文
posted @ 2011-05-21 20:40 class 阅读(368) 评论(0) 推荐(0) 编辑
摘要: Problem7: By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number?问题7: 通过列出前六个素数:2,3,5,7,11,13,我们可以知道第6个素数为13。 求第10001个素数?方法一: 一个一个数判断是否为素数,知道第n个素数:方法一def f(n): result=[2] i=3 while len(result)<n: for j in result: if i% 阅读全文
posted @ 2011-05-11 15:42 class 阅读(703) 评论(0) 推荐(0) 编辑
摘要: Problem 6: The sum of the squares of the first ten natural numbers is, 12+ 22+ ... + 102= 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2= 552= 3025 Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 30 阅读全文
posted @ 2011-05-06 17:14 class 阅读(774) 评论(0) 推荐(0) 编辑
摘要: Problem 5: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that isevenly divisibleby all of the numbers from 1 to 20?问题5: 2520是最小的能被1到10的所有的数整除的整数。 求最小的能被1到20的所有的数整除的整数。方法一: 本题为求1到n的最小公倍数。 求多个数的最小公倍数,可以先求 阅读全文
posted @ 2011-05-04 12:33 class 阅读(1156) 评论(2) 推荐(0) 编辑
摘要: problem 4: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 9199. Find the largest palindrome made from the product of two 3-digit numbers.问题4: 回文数:将一个数的数字按相反的顺序重新排列后,所得到的数和原来的数一样. 最大的可以表示为两个两位数的乘积的回文数是9009=9199. 求最大的可以表示为两个 阅读全文
posted @ 2011-04-18 22:29 class 阅读(1329) 评论(0) 推荐(0) 编辑