PythonでHousePassword

f:id:g_YUYUYU:20140426205819j:plain

コード3

def checkio(psswd):
	if (len(psswd) >= 10) and (not psswd.islower()) and (not psswd.isupper()) and (not psswd.isalpha()) and (not psswd.isdigit()):
		return True
#処理時間:0.125s

コード2

def checkio(psswd):
    return ( (len(psswd) >= 10) and
             (not psswd.islower()) and
             (not psswd.isupper()) and
             (not psswd.isalpha()) and
             (not psswd.isdigit()))
# 処理時間:0.11s
# Auther SuperDave1342
# http://www.checkio.org/mission/house-password/publications/SuperDave1342/python-27/strong-password/

コード1

def checkio(data):
	if 10 <= len(data) <= 64:
		check = ["1"]
		for i in list(data):
			if i.isdigit():
				check.append("2")
			if i.islower():
				check.append("3")
			if i.isupper():
				check.append("4")
		if "".join(sorted(set(check))) == "1234":
			return True
		else:
			return False
	else:
		return False

checkio('B18daf') #== False
checkio('1111GGGGggg')# == True
checkio('aeaegagawegaeawaga')# == False
checkio('ABCDabcd')# == False
checkio('1234567899999')# == False
checkio('ZeYEd15qqqqqq')# == True

# 処理時間:0.9s

一言

  1. set()で重複要素を削除して、sorted()でバラバラになるかもしれない値をソートして、"".joinでリストを文字列化した。
  2. 自分の書いたコードはAuther SuperDave1342さんの書いたコードよりも9倍遅くて、ハッカーと画家に書かれていた凡人プログラマと天才プログラマの違いを思い出して、ああ~ってなった。