From cda1650e0ead2bc169c38d7bef029cc86269dfd0 Mon Sep 17 00:00:00 2001 From: Gasser Thibaud Date: Fri, 6 Dec 2019 10:19:47 +0100 Subject: [PATCH] Day 4 challenge --- day4/day4.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 day4/day4.py diff --git a/day4/day4.py b/day4/day4.py new file mode 100644 index 0000000..360be68 --- /dev/null +++ b/day4/day4.py @@ -0,0 +1,37 @@ +#! /usr/bin/env python3 + + +def check_increase(number): + num = str(number) + for i in range(len(num) - 1): + if num[i+1] < num[i]: + return False + return True + +def check_adjacent(number): + num = str(number) + for digit in num: + count = num.count(digit) + if count == 2: # Part one : <= 2 + return True + return False + + +def tests(): + assert check_increase(123456) == True + assert check_increase(123454) == False + assert check_adjacent(112345) == True + assert check_adjacent(123445) == True + assert check_adjacent(123456) == False + + +def main(start, end): + matches = 0 + for n in range(start, end + 1): + if check_increase(n) and check_adjacent(n): + matches += 1 + return matches + +if __name__ == "__main__": + tests() + print("Matches : ", main(367479, 893698))