summaryrefslogtreecommitdiffstats
path: root/5/2.py
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-11-24 22:25:42 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-11-24 22:25:42 +0000
commita7a6b86002b595bc167af72606b14c67ed1bdf8f (patch)
treebff94329cf969bd9df68d3b9782fee2107db56c2 /5/2.py
downloadaoc2015-a7a6b86002b595bc167af72606b14c67ed1bdf8f.tar.gz
aoc2015-a7a6b86002b595bc167af72606b14c67ed1bdf8f.tar.xz
aoc2015-a7a6b86002b595bc167af72606b14c67ed1bdf8f.zip
init commit
Diffstat (limited to '5/2.py')
-rw-r--r--5/2.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/5/2.py b/5/2.py
new file mode 100644
index 0000000..a172cdd
--- /dev/null
+++ b/5/2.py
@@ -0,0 +1,24 @@
+from collections import defaultdict
+def check(w):
+ pairs = defaultdict(list)
+ rep = False
+ last2 = (None, None)
+ for i, c in enumerate(w):
+ if last2[1] is not None:
+ pairs[(last2[1], c)].append(i)
+ if not rep and last2[0] == c:
+ rep = True
+ last2 = (last2[1], c)
+ if not rep:
+ return False
+ for _, p in pairs.items():
+ if len(p) < 2:
+ continue
+ if len(p) > 2:
+ break
+ if p[1] - p[0] > 1:
+ break
+ else:
+ return False
+ return True
+print(len([w for w in open('input') if check(w)]))