
python
痞子丐
unix C\C++
展开
-
汉诺塔游戏-递归算法python
'''汉诺塔-递归函数:问题分解AC(n) = AB(n-1) + BC(n-1):例如n=3 先实现A上面(n-1)2个盘移到B,最大的移到C;接下来就是B上的n-1(2个)盘移>到C'''def move(n,a,b,c): if n == 1 : print(a,'->',c) return move(n-1,a,c,b) p原创 2017-02-27 00:47:15 · 381 阅读 · 0 评论 -
埃氏筛法求素数-Python
def _not_divisible(n): #是否整除 return lambda x: x%n > 0def _odd_iter(): #创建奇数序列 n = 1 while True: n += 2 yield ndef primes(end_num): #end_num范围内的素数 if end_num < 2:转载 2017-03-01 23:54:22 · 1981 阅读 · 0 评论 -
回文数的判断-Python
#coding=utf-8def is_palindrome(n): str_n = str(n) return str_n == str_n[-1::-1]#测试ooutput = filter(is_palindrome,range(1,1000))print(list(output))原创 2017-03-02 00:27:48 · 7266 阅读 · 0 评论 -
python的排序模块bisect
转载:原文地址 http://www.cnblogs.com/skydesign/archive/2011/09/02/2163592.html一个python的排序模块bisect,觉得挺有趣的,跟大家分享分享。 先看看模块的结构: 前面五个属性大家感兴趣可以打出来看看数值,这里就不介绍了。 先说明的是,使用转载 2017-04-13 01:17:42 · 436 阅读 · 0 评论 -
最长子字符串-无重复字符
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "原创 2017-08-08 20:26:07 · 318 阅读 · 0 评论