0
0

More than 1 year has passed since last update.

AOJトライに関する知識知見の記録共有:Volume0-0051

Posted at

タスク概要

Differential II

コード実装例

TIPS

  1. 例外処理含む評価パターンを追加
  2. 入力値の小数対応
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: '外力入例'")]]

補遺

残課題

  1. 実行速度の改善(枝刈り、データ構造の見直し等)
  2. 入力値の負数対応
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0