summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2019-12-04 07:13:43 +0100
committerGustav Sörnäs <gusso230@student.liu.se>2019-12-04 07:13:43 +0100
commit00ceae21bd2de413a8ca7cc3ea978fd52cba8c80 (patch)
treef1c3909979b68c076146fd56cd03143edd832770
parenta8df3112a2378aa62ea920f3d202204fc019ad19 (diff)
downloadaoc-00ceae21bd2de413a8ca7cc3ea978fd52cba8c80.tar.gz
Day 4 py
-rw-r--r--solutions/py/04-1.py30
-rw-r--r--solutions/py/04-2.py31
2 files changed, 61 insertions, 0 deletions
diff --git a/solutions/py/04-1.py b/solutions/py/04-1.py
new file mode 100644
index 0000000..23096ec
--- /dev/null
+++ b/solutions/py/04-1.py
@@ -0,0 +1,30 @@
+from collections import Counter
+
+def containsDouble(num):
+ s = str(num)
+ amounts = []
+ for n in (0,1,2,3,4,5,6,7,8,9):
+ amounts.append(s.count(str(n)))
+ c = Counter(amounts)
+ return c[0] + c[1] < 10
+
+def isIncreasing(num):
+ s = str(num)
+ n = int(s[0])
+ for sp in s[1:]:
+ if int(sp) < n:
+ return False
+ n = int(sp)
+ return True
+
+if __name__ == "__main__":
+ amount = 0
+ for n in range(357253, 892942 + 1):
+ if containsDouble(n):
+ if isIncreasing(n):
+ print(n)
+ amount += 1
+ if n % 10000 == 0:
+ pass
+ # print(n)
+ print(amount)
diff --git a/solutions/py/04-2.py b/solutions/py/04-2.py
new file mode 100644
index 0000000..582df1a
--- /dev/null
+++ b/solutions/py/04-2.py
@@ -0,0 +1,31 @@
+from collections import Counter
+
+def containsDouble(num):
+ s = str(num)
+ amounts = []
+ for n in (0,1,2,3,4,5,6,7,8,9):
+ amounts.append(s.count(str(n)))
+ c = Counter(amounts)
+ if c[0] + c[1] < 10:
+ return c[2] >= 1
+
+def isIncreasing(num):
+ s = str(num)
+ n = int(s[0])
+ for sp in s[1:]:
+ if int(sp) < n:
+ return False
+ n = int(sp)
+ return True
+
+if __name__ == "__main__":
+ amount = 0
+ for n in range(357253, 892942 + 1):
+ if containsDouble(n):
+ if isIncreasing(n):
+ print(n)
+ amount += 1
+ if n % 10000 == 0:
+ pass
+ # print(n)
+ print(amount)