summaryrefslogtreecommitdiffstats
path: root/solutions
diff options
context:
space:
mode:
Diffstat (limited to 'solutions')
-rw-r--r--solutions/py/d04.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/solutions/py/d04.py b/solutions/py/d04.py
index 5628925..6b2af1d 100644
--- a/solutions/py/d04.py
+++ b/solutions/py/d04.py
@@ -12,35 +12,37 @@ def isIncreasing(num):
def pt1(input):
def containsDouble(num):
s = str(num)
- amounts = []
- for n in (0,1,2,3,4,5,6,7,8,9): # herregud
- amounts.append(s.count(str(n)))
+ amounts = [0 for _ in range(10)]
+ for c in s:
+ amounts[int(c)] += 1
c = Counter(amounts)
return c[0] + c[1] < 10
amount = 0
for n in range(357253, 892942 + 1):
- if containsDouble(n):
- if isIncreasing(n):
+ if isIncreasing(n):
+ if containsDouble(n):
amount += 1
return amount
def pt2(input):
def containsDouble(num):
s = str(num)
- amounts = []
- for n in (0,1,2,3,4,5,6,7,8,9): # herregud
- amounts.append(s.count(str(n)))
+ amounts = [0 for _ in range(10)]
+ for c in s:
+ amounts[int(c)] += 1
c = Counter(amounts)
if c[0] + c[1] < 10:
return c[2] >= 1
+
amount = 0
for n in range(357253, 892942 + 1):
- if containsDouble(n):
- if isIncreasing(n):
+ if isIncreasing(n):
+ if containsDouble(n):
amount += 1
return amount
if __name__ == "__main__":
import cProfile
cProfile.run("pt1([])")
+ cProfile.run("pt2([])")