This commit is contained in:
dave 2019-12-08 10:33:28 -08:00
commit 7a0b0a1e7f
2 changed files with 70 additions and 0 deletions

31
4/a.py Normal file
View File

@ -0,0 +1,31 @@
data = "172930-683082".split("-")
min_, max_ = int(data[0]), int(data[1])
def validate(num):
repeat = False
nums = str(num)
# print(nums)
for i, c in enumerate(nums):
if i == len(nums) - 1:
break
# print(i, len(nums))
nextc = nums[i + 1]
if nextc < c:
# print(f"not increasing, {nextc} < {c}")
return False # not increasing
if c == nextc:
# print("found repeat")
repeat = True
return repeat
matches = 0
for i in range(min_, max_):
if validate(i):
matches += 1
print(matches)
# print(validate(123466))

39
4/b.py Normal file
View File

@ -0,0 +1,39 @@
data = "172930-683082".split("-")
min_, max_ = int(data[0]), int(data[1])
def validate(num):
repeats = False
repeats_twice = False
repeatlen = 0
lastc = None
nums = str(num)
for i, c in enumerate(nums):
if lastc:
if c < lastc:
return False # not rising
if c == lastc:
repeats = True
if repeatlen == 0:
repeatlen = 2
else:
repeatlen += 1
else:
if repeatlen == 2:
repeats_twice = True
repeatlen = 0
lastc = c
return repeats and (repeats_twice or repeatlen == 2)
matches = 0
for i in range(min_, max_):
if validate(i):
matches += 1
print(matches)
# print(validate(123466))