From c41a4c2037b0da6c4e9d9ccbc3057ba690faa661 Mon Sep 17 00:00:00 2001 From: Ben Charlton Date: Fri, 6 Dec 2019 13:03:45 +0000 Subject: [PATCH] day4 --- 4/4-2.py | 27 +++++++++++++++++++++++++++ 4/4.py | 19 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 4/4-2.py create mode 100755 4/4.py diff --git a/4/4-2.py b/4/4-2.py new file mode 100755 index 0000000..2b1e794 --- /dev/null +++ b/4/4-2.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import sys + +start = 125730 +end = 579381 + +for x in range(start, end+1): + s = str(x) + fail=False + double=False + matchcount = 1 + for n in range(0,5): + if s[n] > s[n+1]: + fail = True + break + if s[n] == s[n+1]: + matchcount += 1 + else: + if matchcount == 2: + double = True + matchcount = 1 + + if matchcount == 2: + double = True + if double and not fail: + print(x) \ No newline at end of file diff --git a/4/4.py b/4/4.py new file mode 100755 index 0000000..92754d1 --- /dev/null +++ b/4/4.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +import sys + +start = 125730 +end = 579381 + +for x in range(start, end+1): + s = str(x) + fail=False + double=False + for n in range(0,5): + if s[n] > s[n+1]: + fail = True + break + if s[n] == s[n+1]: + double = True + if double and not fail: + print(x) \ No newline at end of file