我試圖強行推銷代碼問題,並且我遇到了一些問題。試圖解決Python中的PIN算法
http://alvaray.org/brute-forcing-pincode-keypads-using-combinatorial-mathematics/
我包括鏈接討論我試圖解決這個確切的問題。現在它在頁面上包含了一個鏈接到公式的鏈接,但是我正在嘗試創建自己的鏈接而不使用它們。我的目標是將其從40,000個組合時期中縮短。如果我能達到10,003這將是很酷的,但是,最終目標是將其從最大值縮短。 我的代碼如下所示:
import random
codes = []
shortest_combination = []
one_big_string = []
garbage_string = []
for a in range(0,10):
for b in range(0,10):
for c in range(0,10):
for d in range(0,10):
codes.append(str(a) + str(b) + str(c) + str(d))
random.shuffle(codes)
shortest_combination.append(codes[0:1])
codes.remove(codes[0:1])
"".join(shortest_combination)
for code in codes:
for short in shortest_combination:
codes.index(short[short + 1:len(short)])
find = shortest_combination.append(codes[short: len(short) + 1])
codes.remove(find)
"".join(shortest_combination)
print shortest_combination
不幸的是我得到這個錯誤: ValueError異常:list.remove(X):X不在列表中 我不知道我是我用錯了刪除?請幫助,加上關於如果我接近問題的任何反饋也是有幫助的。謝謝
哇哈哈哈我是白癡,謝謝你的工作。現在代碼的其餘部分是完全不同的困境。再次感謝 – Vantheman6 2015-02-24 20:27:11