19 "comment_mark = re.compile('<[^>]*>')\n",
20 "expand_mark = re.compile(':(\\d+):(\\d+):')"
29 "def decomment(text):\n",
30 " m = comment_mark.search(text)\n",
34 " text = text[:s] + text[e:]\n",
35 " m = comment_mark.search(text)\n",
45 "def expand(text, expansion_limit=None):\n",
47 " m = expand_mark.search(text)\n",
48 " while m and (expansion_limit is None or (expansion_limit is not None and i <= expansion_limit)):\n",
49 " l = int(m.group(1))\n",
50 " n = int(m.group(2))\n",
55 " text = text[:s-l] + text[s-l:s] * n + text[e:]\n",
56 " m = expand_mark.search(text)\n",
63 "execution_count": 29,
67 "data_p_t = [l.strip() for l in open('../../data/05-instructions.txt')]"
72 "execution_count": 30,
76 "data_p = [decomment(l) for l in data_p_t]\n",
77 "data = [expand(l) for l in data_p]"
82 "execution_count": 31,
91 "execution_count": 31,
93 "output_type": "execute_result"
97 "len([c for c in ''.join(data_p) if c not in string.whitespace])"
102 "execution_count": 32,
111 "execution_count": 32,
113 "output_type": "execute_result"
117 "len([c for c in ''.join(data) if c not in string.whitespace])"
122 "execution_count": 33,
126 "data_s_p_t = open('../../data/05-instructions.txt').read()\n",
127 "data_s_p = decomment(data_s_p_t)\n",
128 "data_s = expand(data_s_p)"
133 "execution_count": 34,
142 "execution_count": 34,
144 "output_type": "execute_result"
148 "sum(1 for c in data_s_p if c not in string.whitespace)"
153 "execution_count": 35,
162 "execution_count": 35,
164 "output_type": "execute_result"
168 "sum(1 for c in data_s if c not in string.whitespace)"
173 "execution_count": 36,
178 "output_type": "stream",
180 "27.5 ms ± 951 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
186 "data_p = [decomment(l) for l in data_p_t]\n",
187 "data = [expand(l) for l in data_p]"
192 "execution_count": 37,
197 "output_type": "stream",
199 "875 ms ± 5.02 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
205 "data_s_p = decomment(data_s_p_t)\n",
206 "data_s = expand(data_s_p)"
211 "execution_count": null,
219 "display_name": "Python 3",
220 "language": "python",
228 "file_extension": ".py",
229 "mimetype": "text/x-python",
231 "nbconvert_exporter": "python",
232 "pygments_lexer": "ipython3",