-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresults.py
48 lines (41 loc) · 1.38 KB
/
results.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/python3
# vim: set tabstop=4 shiftwidth=4 expandtab :
# Generated by letscode
"""Results under a nice format"""
from __future__ import print_function
import re
PE_URL = "[%s](https://projecteuler.net/problem=%d)"
GITUHB_URL = "[%s](https://github.com/SylvainDe/ProjectEulerPython/blob/master/euler.py#L%d)"
NB_PROB = 500
RE_DEF = re.compile('^def euler([0-9]+)\(')
RE_TEST = re.compile('\(euler([0-9]+),')
def main():
# Get data
definitions, tests = {}, {}
with open('euler.py') as f:
lines = f.readlines()
for i, l in enumerate(lines):
l = l.strip()
i += 1
m = re.match(RE_DEF, l)
if m:
n = int(m.groups()[0])
assert n not in definitions
definitions[n] = i
m = re.match(RE_TEST, l)
if m:
n = int(m.groups()[0])
tests.setdefault(n, []).append(i)
# Check data
assert tests.keys() == definitions.keys()
assert all(1 <= i < NB_PROB for i in tests)
# Print data
for i in range(1, NB_PROB):
links = [PE_URL % ("Problem " + str(i), i)]
if i in definitions:
links.append(GITUHB_URL % ("Solution", definitions[i]))
links.extend(GITUHB_URL % ("Test", t) for t in tests.get(i, []))
print(" ".join(links))
print()
if __name__ == "__main__":
main()