23 "def increment(password):\n",
25 " if password[-1] < 'z':\n",
26 " return password[:-1] + chr(ord(password[-1]) + 1)\n",
28 " return increment(password[:-1]) + 'a'\n",
30 " raise StopIterations\n"
48 "output_type": "execute_result"
70 "output_type": "execute_result"
74 "increment('aaazzzzz')"
85 "def valid(password):\n",
86 " if 'i' in password:\n",
88 " if 'o' in password:\n",
90 " if 'l' in password:\n",
92 " if not has_run(password):\n",
94 " if len(doubles(password)) < 2:\n",
101 "execution_count": 21,
107 "def has_run(password):\n",
108 " for i in range(len(password) - 3):\n",
109 " if ord(password[i]) + 1 == ord(password[i+1]) and ord(password[i+1]) + 1 == ord(password[i+2]):\n",
116 "execution_count": 20,
127 "execution_count": 20,
129 "output_type": "execute_result"
133 "has_run('hiajkblammnpo')"
138 "execution_count": 24,
144 "def doubles(password):\n",
146 " for i in range(len(password)-1):\n",
147 " if password[i] == password[i+1]:\n",
148 " ds += [password[i]]\n",
154 "execution_count": 27,
165 "execution_count": 27,
167 "output_type": "execute_result"
171 "doubles('hiajkkblammmnpo')"
176 "execution_count": 30,
187 "execution_count": 30,
189 "output_type": "execute_result"
198 "execution_count": 31,
204 "def next_valid(password):\n",
205 " p = increment(password)\n",
206 " while not valid(p):\n",
207 " p = increment(p)\n",
213 "execution_count": 32,
224 "execution_count": 32,
226 "output_type": "execute_result"
230 "next_valid('abcdefgh')"
235 "execution_count": 33,
246 "execution_count": 33,
248 "output_type": "execute_result"
252 "next_valid('ghijklmn')"
257 "execution_count": 34,
268 "execution_count": 34,
270 "output_type": "execute_result"
274 "next_valid('hxbxwxba')"
279 "execution_count": 35,
290 "execution_count": 35,
292 "output_type": "execute_result"
296 "next_valid('hxbxxyzz')"
301 "execution_count": null,
311 "display_name": "Python 3",
312 "language": "python",
320 "file_extension": ".py",
321 "mimetype": "text/x-python",
323 "nbconvert_exporter": "python",
324 "pygments_lexer": "ipython3",