Noëlle Anthony 5年前
コミット
dcba549a45
2個のファイルの変更59行の追加0行の削除
  1. 26
    0
      2019/04a.py
  2. 33
    0
      2019/04b.py

+ 26
- 0
2019/04a.py ファイルの表示

# Python 3.7

def main():
rangeStart = 109165
rangeEnd = 576723
count = 0
for pw in range(rangeStart, rangeEnd):
count += validatePassword(pw)
print(count)

def validatePassword(pw):
pwStr = str(pw)
# does it have a doubled digit
# does it have a descending digit
c, d = 0, 0
for i in range(1, len(pwStr)):
if pwStr[i-1] == pwStr[i]:
c = 1
if int(pwStr[i]) < int(pwStr[i-1]):
d = 1
if c == 0 or d == 1:
return 0
return 1

if __name__ == "__main__":
main()

+ 33
- 0
2019/04b.py ファイルの表示

# Python 3.7

def main():
rangeStart = 109165
rangeEnd = 576723
count = 0
for pw in range(rangeStart, rangeEnd):
count += validatePassword(pw)
print(count)

def validatePassword(pw):
pwStr = str(pw)
# does it have a doubled digit
# but not a tripled etc. digit!
# does it have a descending digit
c, d, m = 0, 0, ""
for i in range(1, len(pwStr)):
if pwStr[i-1] == pwStr[i]:
if c == 0 and m == "": # it has a doubled digit we haven't seen before
c = 1
m = pwStr[i]
elif c == 1 and m == pwStr[i]: # it has a doubled digit we HAVE seen before
c = 0 # so it doesn't count :(
else: # this digit isn't the same as the previous, so reset the memo
m = ""
if int(pwStr[i]) < int(pwStr[i-1]):
d = 1
if c == 0 or d == 1:
return 0
return 1

if __name__ == "__main__":
main()

読み込み中…
キャンセル
保存