国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python 窮舉指定長度的密碼例子

瀏覽:2日期:2022-07-31 13:14:12

本程序可根據給定的字符字典,窮舉指定長度的所有字符串:

def get_pwd(str, num): if(num == 1): for x in str: yield x else: for x in str: for y in get_pwd(str, num-1): yield x+y strKey='abc'for x in get_pwd(strKey,3): print x

結果:

aaaaabaacabaabbabcacaacbaccbaababbacbbabbbbbcbcabcbbcccaacabcaccbacbbcbcccaccbccc

本程序占用內存小,生成速度快,歡迎嘗試?。。?/p>

補充知識:Python 窮舉法, 二分法 與牛頓-拉夫遜方法求解平方根的性能對比

窮舉法, 二分法 與牛頓-拉夫遜方法求解平方根的優劣,從左到右依次遞優。

經過測試,窮舉法基本超過 1 分鐘,還沒有出數據;

二分法只要區區1秒不到就出結果了。

牛頓-拉夫遜是秒出,沒有任何的停頓。

numberTarget =int(input('Please enter a number:'))numberSqureRoot = 0while(numberSqureRoot<abs(numberTarget)): if numberSqureRoot**2 >= abs(numberTarget): break numberSqureRoot = numberSqureRoot + 1if numberSqureRoot**2 != numberTarget: print('Your number %s is not a perfect squre, the square root is %s ' % ( numberTarget,numberSqureRoot) )else: if numberTarget < 0 : numberSqureRoot = -numberSqureRoot print('Your number %s is a perfect squre, the square root is %s ' % ( numberTarget, numberSqureRoot))print('now we begin to calculate the binary search...')numberTarget=int(input('Please enter the number for binary search...'))numberSqureRoot = 0lowValue = 0.0highValue=numberTarget*1.0epsilon = 0.01numberSqureRoot = (highValue + lowValue)/2while abs(numberSqureRoot**2 - numberTarget) >=epsilon: print('lowValue:%s, highValue:%s, currentValue:%s'%(lowValue,highValue,numberSqureRoot)) if numberSqureRoot**2<numberTarget: lowValue=numberSqureRoot else: highValue=numberSqureRoot numberSqureRoot = (lowValue+highValue) /2print('The number %s has the squre root as %s ' %(numberTarget,numberSqureRoot))print('now we begin to calculate the newTon search...')numberTarget=int(input('Please enter the number for newTon search...'))numberSqureRoot = 0epsilon = 0.01k=numberTargetnumberSqureRoot = k/2.0while( abs(numberSqureRoot*numberSqureRoot - k)>=epsilon): numberSqureRoot=numberSqureRoot-(((numberSqureRoot**2) - k)/(2*numberSqureRoot))print('squre root of %s is %s ' %(numberTarget,numberSqureRoot))

以上這篇python 窮舉指定長度的密碼例子就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 林芝县| 牙克石市| 井陉县| 青岛市| 星子县| 澎湖县| 南汇区| 汉源县| 剑川县| 岳池县| 永安市| 松潘县| 昭觉县| 甘肃省| 德江县| 郁南县| 潞西市| 筠连县| 衡山县| 衡阳县| 台州市| 五大连池市| 永昌县| 定南县| 翁牛特旗| 郑州市| 项城市| 平阳县| 五华县| 铜鼓县| 且末县| 惠水县| 金门县| 都江堰市| 房产| 广州市| 蕉岭县| 年辖:市辖区| 泰顺县| 肇州县| 新安县|