projects
/
summerofcode2018soln.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Mucking around with task 5
[summerofcode2018soln.git]
/
src
/
task5
/
task5-nore.ipynb
diff --git
a/src/task5/task5-nore.ipynb
b/src/task5/task5-nore.ipynb
index d40bec67e2a527a7eb6d4ec85a89273c75cf9ff5..7fdcae6cda2e7580839ff351936952cdfbb78c77 100644
(file)
--- a/
src/task5/task5-nore.ipynb
+++ b/
src/task5/task5-nore.ipynb
@@
-30,7
+30,7
@@
"metadata": {},
"outputs": [],
"source": [
"metadata": {},
"outputs": [],
"source": [
- "def decomment
_no_re
(text):\n",
+ "def decomment(text):\n",
" s, e = find_comment(text)\n",
" while s is not None:\n",
" text = text[:s] + text[e+1:]\n",
" s, e = find_comment(text)\n",
" while s is not None:\n",
" text = text[:s] + text[e+1:]\n",
@@
-53,22
+53,21
@@
" if end > -1:\n",
" length = int(text[start+1:mid])\n",
" times = int(text[mid+1:end])\n",
" if end > -1:\n",
" length = int(text[start+1:mid])\n",
" times = int(text[mid+1:end])\n",
- " if length > start:\n",
- " length = start\n",
" return start, end, length, times\n",
" return None, None, None, None"
]
},
{
"cell_type": "code",
" return start, end, length, times\n",
" return None, None, None, None"
]
},
{
"cell_type": "code",
- "execution_count":
1
5,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"metadata": {},
"outputs": [],
"source": [
- "def expand
_no_re
(text, expansion_limit=None):\n",
+ "def expand(text, expansion_limit=None):\n",
" i = 1\n",
" s, e, l, n = find_expansion_mark(text)\n",
" while s is not None and (expansion_limit is None or (expansion_limit is not None and i <= expansion_limit)):\n",
" i = 1\n",
" s, e, l, n = find_expansion_mark(text)\n",
" while s is not None and (expansion_limit is None or (expansion_limit is not None and i <= expansion_limit)):\n",
+ " if l > s: l = s\n",
" text = text[:s-l] + text[s-l:s] * n + text[e+1:]\n",
" s, e, l, n = find_expansion_mark(text)\n",
" i += 1\n",
" text = text[:s-l] + text[s-l:s] * n + text[e+1:]\n",
" s, e, l, n = find_expansion_mark(text)\n",
" i += 1\n",
@@
-77,7
+76,7
@@
},
{
"cell_type": "code",
},
{
"cell_type": "code",
- "execution_count":
1
6,
+ "execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"metadata": {},
"outputs": [],
"source": [
@@
-86,17
+85,17
@@
},
{
"cell_type": "code",
},
{
"cell_type": "code",
- "execution_count":
1
7,
+ "execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"metadata": {},
"outputs": [],
"source": [
- "data_p = [decomment
_no_re
(l) for l in data_p_t]\n",
- "data = [expand
_no_re
(l) for l in data_p]"
+ "data_p = [decomment(l) for l in data_p_t]\n",
+ "data = [expand(l) for l in data_p]"
]
},
{
"cell_type": "code",
]
},
{
"cell_type": "code",
- "execution_count":
1
8,
+ "execution_count": 8,
"metadata": {},
"outputs": [
{
"metadata": {},
"outputs": [
{
@@
-105,7
+104,7
@@
"149043"
]
},
"149043"
]
},
- "execution_count":
1
8,
+ "execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
"metadata": {},
"output_type": "execute_result"
}
@@
-116,7
+115,7
@@
},
{
"cell_type": "code",
},
{
"cell_type": "code",
- "execution_count":
1
9,
+ "execution_count": 9,
"metadata": {},
"outputs": [
{
"metadata": {},
"outputs": [
{
@@
-125,7
+124,7
@@
"302266"
]
},
"302266"
]
},
- "execution_count":
1
9,
+ "execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
"metadata": {},
"output_type": "execute_result"
}
@@
-141,8
+140,8
@@
"outputs": [],
"source": [
"data_s_p_t = open('../../data/05-instructions.txt').read()\n",
"outputs": [],
"source": [
"data_s_p_t = open('../../data/05-instructions.txt').read()\n",
- "data_s_p = decomment
_no_re
(data_s_p_t)\n",
- "data_s = expand
_no_re
(data_s_p)"
+ "data_s_p = decomment(data_s_p_t)\n",
+ "data_s = expand(data_s_p)"
]
},
{
]
},
{
@@
-194,14
+193,14
@@
"name": "stdout",
"output_type": "stream",
"text": [
"name": "stdout",
"output_type": "stream",
"text": [
- "2
3.7 ms ± 1.79
ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
+ "2
2.7 ms ± 1.6
ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"%%timeit\n",
]
}
],
"source": [
"%%timeit\n",
- "data_p = [decomment
_no_re
(l) for l in data_p_t]\n",
- "data = [expand
_no_re
(l) for l in data_p]"
+ "data_p = [decomment(l) for l in data_p_t]\n",
+ "data = [expand(l) for l in data_p]"
]
},
{
]
},
{
@@
-213,14
+212,14
@@
"name": "stdout",
"output_type": "stream",
"text": [
"name": "stdout",
"output_type": "stream",
"text": [
- "3
60 ms ± 6.67
ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
+ "3
54 ms ± 7.34
ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
"source": [
"%%timeit\n",
]
}
],
"source": [
"%%timeit\n",
- "data_s_p = decomment
_no_re
(data_s_p_t)\n",
- "data_s = expand
_no_re
(data_s_p)"
+ "data_s_p = decomment(data_s_p_t)\n",
+ "data_s = expand(data_s_p)"
]
},
{
]
},
{