Skip to content

Commit ff8238f

Browse files
committed
Add the solution for the Day04 part 02
1 parent 13708df commit ff8238f

File tree

2 files changed

+64
-16
lines changed

2 files changed

+64
-16
lines changed

.idea/workspace.xml

Lines changed: 31 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Day04/solution_part2.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
def is_increasing_digits_sequence(number):
2+
sequence = list(map(int, str(number)))
3+
for n in sequence:
4+
for i in range(0, 5):
5+
if int(sequence[i+1]) < int(sequence[i]):
6+
return False
7+
return True
8+
9+
10+
def is_equal_digits(number):
11+
sequence = list(map(int, str(number)))
12+
count_n = {}
13+
for i in range(0, 6):
14+
if int(sequence[i]) not in count_n.keys():
15+
count_n[int(sequence[i])] = 1
16+
elif int(sequence[i]) in count_n.keys():
17+
count_n[int(sequence[i])] += 1
18+
if any(value == 2 for value in count_n.values()):
19+
# print("Double found:", count_n)
20+
return True
21+
return False
22+
23+
24+
with open(f"data.txt") as f:
25+
content = f.readlines()
26+
numbers = [x.strip() for x in content][0].split("-")
27+
numbers = [int(x) for x in numbers]
28+
list_numbers = list(range(numbers[0], numbers[1] + 1))
29+
result_n = 0
30+
for number in list_numbers:
31+
if is_increasing_digits_sequence(number) is True & is_equal_digits(number) is True:
32+
result_n += 1
33+
print("Result:", result_n)

0 commit comments

Comments
 (0)