aoc

commit 88d4365d2ec0bba97fcdf3735078a91f17f61613

Author: Honza Pokorny <me@honza.ca>

moar

 004/main.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++


diff --git a/004/main.py b/004/main.py
new file mode 100644
index 0000000000000000000000000000000000000000..f98201e499710e15f0671e534c54a9bfc43b6e44
--- /dev/null
+++ b/004/main.py
@@ -0,0 +1,53 @@
+def has_double(n):
+    s = str(n)
+    o = {}
+
+    for d in s:
+        if d not in o:
+            o[d] = 1
+        else:
+            o[d] += 1
+
+    for v in o.values():
+        if v == 2:
+            return True
+
+    return False
+
+
+def does_increase(n):
+    s = str(n)
+    p = 0
+
+    for d in s:
+        dd = int(d)
+
+        if dd < p:
+            return False
+
+        p = dd
+
+    return True
+
+
+def matches(n):
+    return has_double(n) and does_increase(n)
+
+
+def main():
+    assert matches(112233)
+    assert not matches(123444)
+    assert matches(111122)
+
+    # return
+
+    c = 0
+    for n in range(172930, 683082):
+        if matches(n):
+            c += 1
+
+    print(c)
+
+
+if __name__ == '__main__':
+    main()