タスク概要
Secret Number
コード実装例
TIPS
- 例外処理含む評価パターンを追加
import pprint, sys, time, re
def core(arg, adv=True):
if adv:
s = ""
for ch in arg:
if ch.isdigit():
s = s + ch
else:
s = s + " "
else:
s = re.sub(r'[^0-9]', ' ', arg)
l = [int(v) for v in s.split(" ") if v != ""]
return [sum(l), l]
def app(*args):
ret = []
for arg in args:
s = []
for adv in [False, True]:
st = time.time()
try:
r = core(arg, adv=adv)
except Exception as e:
r = e
s.append([adv, round(time.time() - st, 6), r])
ret.append([arg, s])
return ret
print(sys.version)
pprint.pprint(app(
# basic examples
"""Thereare100yenonthetable.Iam17yearsold.
Ishouldgohomeat6pm.""",
# additional examples
"""hog e-1.2ほげ0""",
# exceptional examples
))
実行結果
各種補足情報出力(入力値FB、デバッグログ等)含む
3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0]
[['Thereare100yenonthetable.Iam17yearsold.\nIshouldgohomeat6pm.',
[[False, 0.000151, [123, [100, 17, 6]]],
[True, 1.8e-05, [123, [100, 17, 6]]]]],
['hog e-1.2ほげ0',
[[False, 1e-05, [3, [1, 2, 0]]], [True, 5e-06, [3, [1, 2, 0]]]]]]
補遺
残課題(Pull Request絶賛募集中!)
- 実行速度の改善(枝刈り、データ構造の見直し等)
- コア関数の汎用化