0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

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

Posted at

タスク概要

Secret Number

コード実装例

TIPS

  1. 例外処理含む評価パターンを追加
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絶賛募集中!)

  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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?