-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathday_04a.py
More file actions
38 lines (30 loc) · 756 Bytes
/
day_04a.py
File metadata and controls
38 lines (30 loc) · 756 Bytes
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
#!/usr/bin/python3
import sys
def meetsConditions(num):
prev_val = 10
repeat = False
while num > 0:
val = num % 10
num = int(num / 10)
if val > prev_val:
return False
if prev_val == val:
repeat = True
prev_val = val
return repeat
def main():
# Get input
file_name = "../input/day_04_input"
if len(sys.argv) > 1:
file_name = sys.argv[1]
file = open(file_name)
val_range = [int(ele) for ele in file.readline().strip("\n").split("-")]
# Solve
count = 0
for num in range(val_range[0], val_range[1] + 1):
if meetsConditions(num):
count += 1
print(count)
return count
if __name__ == "__main__":
main()