-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (52 loc) · 1.03 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python3
first = 158126
last = 624574
def hasDouble(i):
current = i % 10
while i > 0:
i = i // 10
if i % 10 == current:
return True
current = i % 10
return False
def hasDoubleNotTriple(i):
current = i % 10
count = 1
while i > 0:
i = i // 10
if i % 10 == current:
count += 1
continue
if count == 2:
return True
current = i % 10
count = 1
return False
def hasDecreasing(i):
current = i % 10
while i > 0:
i = i // 10
if i % 10 > current:
return True
current = i % 10
return False
def stage1():
count = 0
for i in range(first, last):
if not hasDouble(i):
continue
if hasDecreasing(i):
continue
count += 1
return count
def stage2():
count = 0
for i in range(first, last):
if not hasDoubleNotTriple(i):
continue
if hasDecreasing(i):
continue
count += 1
return count
print('[Stage1] %d passwords meet this criteria.' % stage1())
print('[Stage2] %d passwords meet this criteria.' % stage2())