Fixed typo
[advent-of-code-15.git] / advent05.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 1,
6 "metadata": {
7 "collapsed": true
8 },
9 "outputs": [],
10 "source": [
11 "pi5 = open('advent05.txt').read().strip()"
12 ]
13 },
14 {
15 "cell_type": "code",
16 "execution_count": 2,
17 "metadata": {
18 "collapsed": true
19 },
20 "outputs": [],
21 "source": [
22 "def nice(str):\n",
23 " n1 = len(list(c for c in str if c in \"aeiou\")) >= 3\n",
24 " n2 = any(str[i-1] == str[i] for i in range(1, len(str)))\n",
25 " n3 = all(s not in str for s in ['ab', 'cd', 'pq', 'xy'])\n",
26 " return n1 and n2 and n3 "
27 ]
28 },
29 {
30 "cell_type": "code",
31 "execution_count": 3,
32 "metadata": {
33 "collapsed": false
34 },
35 "outputs": [
36 {
37 "data": {
38 "text/plain": [
39 "False"
40 ]
41 },
42 "execution_count": 3,
43 "metadata": {},
44 "output_type": "execute_result"
45 }
46 ],
47 "source": [
48 "nice('dvszwmarrgswjxmb')"
49 ]
50 },
51 {
52 "cell_type": "code",
53 "execution_count": 4,
54 "metadata": {
55 "collapsed": false
56 },
57 "outputs": [
58 {
59 "data": {
60 "text/plain": [
61 "255"
62 ]
63 },
64 "execution_count": 4,
65 "metadata": {},
66 "output_type": "execute_result"
67 }
68 ],
69 "source": [
70 "sum(1 if nice(str.strip()) else 0 for str in pi5.splitlines())"
71 ]
72 },
73 {
74 "cell_type": "code",
75 "execution_count": 5,
76 "metadata": {
77 "collapsed": true
78 },
79 "outputs": [],
80 "source": [
81 "def nice2(st):\n",
82 " def n1(st):\n",
83 " for i in range(1, len(st)):\n",
84 " if st.find(st[i-1:i+1], i+1) > -1:\n",
85 " return True\n",
86 " return False\n",
87 " def n2(st):\n",
88 " return any(st[i-1] == st[i+1] for i in range(1, len(st)-1))\n",
89 " return n1(st) and n2(st)"
90 ]
91 },
92 {
93 "cell_type": "code",
94 "execution_count": 6,
95 "metadata": {
96 "collapsed": false
97 },
98 "outputs": [
99 {
100 "data": {
101 "text/plain": [
102 "False"
103 ]
104 },
105 "execution_count": 6,
106 "metadata": {},
107 "output_type": "execute_result"
108 }
109 ],
110 "source": [
111 "nice2('ieodomkazucvgmuy')"
112 ]
113 },
114 {
115 "cell_type": "code",
116 "execution_count": 7,
117 "metadata": {
118 "collapsed": false
119 },
120 "outputs": [
121 {
122 "data": {
123 "text/plain": [
124 "['ac', 'bd', 'ce', 'df']"
125 ]
126 },
127 "execution_count": 7,
128 "metadata": {},
129 "output_type": "execute_result"
130 }
131 ],
132 "source": [
133 "['abcdef'[i-1] + 'abcdef'[i+1] for i in range(1, len('abcdef')-1)]"
134 ]
135 },
136 {
137 "cell_type": "code",
138 "execution_count": 8,
139 "metadata": {
140 "collapsed": false
141 },
142 "outputs": [
143 {
144 "data": {
145 "text/plain": [
146 "55"
147 ]
148 },
149 "execution_count": 8,
150 "metadata": {},
151 "output_type": "execute_result"
152 }
153 ],
154 "source": [
155 "sum(1 if nice2(st.strip()) else 0 for st in pi5.splitlines())"
156 ]
157 },
158 {
159 "cell_type": "code",
160 "execution_count": null,
161 "metadata": {
162 "collapsed": true
163 },
164 "outputs": [],
165 "source": []
166 }
167 ],
168 "metadata": {
169 "kernelspec": {
170 "display_name": "Python 3",
171 "language": "python",
172 "name": "python3"
173 },
174 "language_info": {
175 "codemirror_mode": {
176 "name": "ipython",
177 "version": 3
178 },
179 "file_extension": ".py",
180 "mimetype": "text/x-python",
181 "name": "python",
182 "nbconvert_exporter": "python",
183 "pygments_lexer": "ipython3",
184 "version": "3.4.3"
185 }
186 },
187 "nbformat": 4,
188 "nbformat_minor": 0
189 }