Skip to content

Commit

Permalink
Day 4
Browse files Browse the repository at this point in the history
  • Loading branch information
shin- committed Dec 4, 2019
1 parent 01e40a1 commit b11927d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/day4.py
@@ -0,0 +1,21 @@
code_range = (356261, 846304)

part1_count = 0
part2_count = 0
for num in range(*code_range):
digits = [int(x) for x in str(num)]
has_adjacents = False
groups = {}
for index, d in enumerate(digits):
if index < 5:
if digits[index + 1] == d:
has_adjacents = True
groups[d] = groups[d] + 1 if d in groups else 2
if digits[index + 1] < d:
break
if index == 5 and has_adjacents:
part1_count += 1
if any([c == 2 for c in groups.values()]):
part2_count += 1

print(f'Part 1 count: {part1_count}, Part 2 count: {part2_count}')

0 comments on commit b11927d

Please sign in to comment.