From 8e2e692e34615a378014709bf831829ab5df3ea2 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 3 Dec 2019 23:32:47 -0700 Subject: [PATCH] answer that I dont understand is wrong --- Day 4/code.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Day 4/code.py diff --git a/Day 4/code.py b/Day 4/code.py new file mode 100644 index 0000000..af3919f --- /dev/null +++ b/Day 4/code.py @@ -0,0 +1,37 @@ +start = 272091 +end = 815432 + +index = start + +count = 0 + + +def ascending(index): + for i in range(len(str(index)) - 1): + + a, b = str(index)[i], str(index)[i + 1] + + if a > b: + index += 10 ** (len(str(index)) - i - 2) * abs(int(b) - int(a)) + return ascending(index) + break + return index + + +while True: + index = ascending(index) + + if index > end: + break + + for i in range(len(str(index)) - 1): + a, b = str(index)[i], str(index)[i + 1] + + if a == b: + count += 1 + print(index) + break + + index += 1 + +print(count)