-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht_euler_problem.py
More file actions
43 lines (39 loc) · 1.25 KB
/
t_euler_problem.py
File metadata and controls
43 lines (39 loc) · 1.25 KB
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Usage: ./t_euler_problem.py [problem_id*]
"""
import sys
import re # regex
import importlib
from os import listdir
from os.path import isdir, join
target_dir = "./"
def find_and_figure_out_problem():
t_exec_flag = False
for argv_index in range(1, len(sys.argv)):
# print sys.argv[argv_index]
problem_str = sys.argv[argv_index]
problem_id = abs(int(problem_str))
problem_str = str(problem_id) # format begin with 00*
find_str = problem_str
if problem_id < 100:
find_str = "0" + problem_str
if problem_id < 10:
find_str = "0" + find_str
dir_list = [f for f in listdir(target_dir) if isdir(join(target_dir, f))]
for dir_name in dir_list:
pattern = re.compile(r'^' + find_str)
match = pattern.match(dir_name)
if match:
# print find_str
t_exec_flag = True
print dir_name
mo = importlib.import_module(dir_name + '.' + dir_name)
mo.exec_main()
if not t_exec_flag:
print "Not solved."
def exec_main():
find_and_figure_out_problem()
if __name__ == '__main__':
exec_main()