summaryrefslogtreecommitdiffstats
path: root/5/2.py
diff options
context:
space:
mode:
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)]))