タスク概要
Differential II
コード実装例
TIPS
- 例外処理含む評価パターンを追加
- 入力値の小数対応
import pprint, sys, time
import itertools
def core(arg, acc=False):
if acc:
pass
else:
perms = list(itertools.permutations(str(arg)))
M, m = [float("".join(f(perms))) for f in [max, min]]
return [M, m, M - m]
def app(*args):
ret = []
for arg in args:
st = time.time()
try:
r = core(arg)
except Exception as e:
r = e
ret.append([arg, round(time.time() - st, 6), r])
return ret
print(sys.version)
pprint.pprint(app(
# basic examples
65539010,
# additional examples
1234.6,
# exceptional examples
"例外入力"
))
実行結果
各種補足情報出力(入力値FB、デバッグログ等)含む
3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 9.4.0]
[[65539010, 0.012844, [96553100.0, 135569.0, 96417531.0]],
[1234.6, 0.000144, [64321.0, 0.12346, 64320.87654]],
['例外入力', 1.3e-05, ValueError("could not convert string to float: '外力入例'")]]
補遺
残課題
- 実行速度の改善(枝刈り、データ構造の見直し等)
- 入力値の負数対応