Skip to content

Commit d427205

Browse files
committed
added 2015/day11
1 parent cafc172 commit d427205

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

2015/day11/answers.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cqjxxyzz
2+
cqkaabcc

2015/day11/input.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cqjxjnds

2015/day11/run.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#! /usr/bin/env python3
2+
3+
def load_data(filename):
4+
with open(filename, 'r') as f:
5+
for line in f:
6+
line = line.rstrip('\n')
7+
yield line
8+
9+
password = next(load_data('input.txt'))
10+
11+
# Part One
12+
13+
def next_valid_after(password):
14+
def next_after(password, i=-1):
15+
a = chr(ord(password[i]) + 1)
16+
carry = False
17+
if a in 'iol':
18+
a = chr(ord(a) + 1)
19+
elif a == chr(ord('z') + 1):
20+
a = 'a'
21+
carry = True
22+
password = password[:i] + a + password[len(password)+i+1:len(password)]
23+
if carry:
24+
return next_after(password, i-1)
25+
return password
26+
def valid(password):
27+
if 'i' in password or 'o' in password or 'l' in password:
28+
return False
29+
pairs = []
30+
straight3 = False
31+
for i in range(1, len(password)):
32+
if password[i] == password[i-1] and len(pairs) < 2:
33+
if not pairs:
34+
pairs.append(i-1)
35+
elif password[pairs[0]] != password[i]:
36+
pairs.append(i-1)
37+
elif ord(password[i]) == ord(password[i-1]) + 1:
38+
if i > 1 and ord(password[i-1]) == ord(password[i-2]) + 1:
39+
straight3 = True
40+
return len(pairs) == 2 and straight3
41+
while password != 'z' * len(password):
42+
password = next_after(password)
43+
if valid(password):
44+
return password
45+
raise Exception("Not found")
46+
47+
result = next_valid_after(password)
48+
49+
print(result)
50+
51+
# Part Two
52+
53+
result = next_valid_after(result)
54+
55+
print(result)
56+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
```
22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
3-
2015 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
3+
2015 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- +
44
2016 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
55
2017 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
66
2018 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- +

0 commit comments

Comments
 (0)