Browse Source

day four part two working, thanks Neui

master
rob loranger 7 months ago
parent
commit
eff0658457
Signed by: Rob Loranger <dev@loranger.xyz> GPG Key ID: D6F1633A4F0903B8
1 changed files with 15 additions and 16 deletions
  1. +15
    -16
      2019/04/p02.py

+ 15
- 16
2019/04/p02.py View File

@@ -1,29 +1,28 @@
combinations = 0
for num in range(124075,580770):
matches = False
digits = list(map(lambda item: int(item), str(num)))
counts = {}
increases = True
for i, x in enumerate(digits):
if i == 0:
counts[x] = 1
continue
# check that we always count up from left to right
if x < digits[i-1]:
matches = False
increases = False
break
# check for doubles that are not part of a larger group
elif x == digits[i-1]:
count = 0
for d in digits[:i]:
if d == x:
count += 1
# count should be one as x is the second digit in a pair
if count == 1:
matches = True
else:
matches = False

if matches == True:
combinations += 1
print(num)
if x in counts:
counts[x] += 1
else:
counts[x] = 1

if increases:
for count in counts.items():
if count[1] == 2:
combinations += 1
print(num)
break


print(f"total combinations: {combinations}")

Loading…
Cancel
Save