|
@@ -3,3 +3,10 @@ with open('data/01.txt', 'r') as file:
|
3
|
3
|
length = len(captcha) // 2
|
4
|
4
|
print('Part one: %s' % sum(int(captcha[i]) for i in range(length) if captcha[i] == captcha[i+1]))
|
5
|
5
|
print('Part two: %s' % sum(int(captcha[i]) for i in range(length) if captcha[i] == captcha[i + length // 2]))
|
|
6
|
+
|
|
7
|
+# Alternatively...
|
|
8
|
+import numpy as np
|
|
9
|
+with open('data/01.txt', 'r') as file:
|
|
10
|
+ captcha = file.readline().strip()
|
|
11
|
+ print('Part one: %s' % sum(int(i) for i, j in zip(captcha, np.roll(list(captcha), 1).tolist()) if i == j))
|
|
12
|
+ print('Part two: %s' % sum(int(i) for i, j in zip(captcha, np.roll(list(captcha), len(captcha)//2).tolist()) if i == j))
|