タスク概要
The Number of Area
コード実装例
TIPS
- 例外処理含む評価パターンを追加
import pprint, sys, time
def core(arg, adv=True):
n = arg
if adv:
ret = int(n * (n + 1) / 2 + 1)
else:
ret = 1 + sum(range(n + 1))
return ret
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
1,
3,
# additional examples
0,
10000,
# exceptional examples
"例外入力"
))
実行結果
各種補足情報出力(入力値FB、デバッグログ等)含む
3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0]
[[1, [[False, 3e-06, 2], [True, 1e-06, 2]]],
[3, [[False, 1e-06, 7], [True, 1e-06, 7]]],
[0, [[False, 1e-06, 1], [True, 0.0, 1]]],
[10000, [[False, 0.00013, 50005001], [True, 1e-06, 50005001]]],
['例外入力',
[[False, 7e-06, TypeError('can only concatenate str (not "int") to str')],
[True, 1e-06, TypeError('can only concatenate str (not "int") to str')]]]]
補遺
残課題(Pull Request絶賛募集中!)
- 実行速度の改善(枝刈り、データ構造の見直し等)