εVтLIàgãεYSym}OIyKå}˜P
入力をリスト(例:)として受け取ります[526,853]
。
オンラインで試すか、範囲内のほとんどのテストケースを確認し[1,999]
てください。
[1,n]
リストがにハードコーディングされ[1,100]
、入力マッピングごとに1回、デカルトリストを2回作成することを除いて、以下の古い回答と同様です。これはパフォーマンスの主なボトルネックです。
古い26バイトの回答は、パフォーマンスに優れています。
Z©bgL®gãUεVXεYSym}OsN>èå}P
このバージョンでは、パフォーマンスを大幅に向上[1,1000]
させて簡単に実行できるように、いくつかのバイトを交換しました。範囲内の数値を含むテストケースは、[1,9999]
TIOで約1秒で実行されます。[10000,99999]
TIOで約10〜15秒の範囲のテストケース。それを超えるとタイムアウトします。
オンラインで試すか、範囲内の数値ですべてのテストケースを検証し[1,9999]
てください。
説明:
Z # Push the max of the (implicit) input-list (without popping)
# i.e. [526,853] → 853
© # Store it in the register (without popping)
b # Convert to binary
# i.e. 853 → 1101010101
g # Take its length
# i.e. 1101010101 → 10
L # Pop and push a list [1, n]
# i.e. 10 → [1,2,3,4,5,6,7,8,9,10]
® # Push the max from the register
g # Take its length
# i.e. 853 → 3
ã # Cartesian product the list that many times
# i.e. [1,2,3,4,5,6,7,8,9,10] and 3
# → [[1,1,1],[1,1,2],[1,1,3],...,[10,10,8],[10,10,9],[10,10,10]]
U # Pop and store it in variable `X`
ε } # Map both values of the input list:
V # Store the current value in variable `Y`
Xε } # Map `y` over the numbers of variable `X`
Y # Push variable `Y`
S # Convert it to a list of digits
# i.e. 526 → [5,2,6]
ym # Take each digit to the power of the current cartesian product sublist
# i.e. [5,2,6] and [3,9,3] → [125,512,216]
O # Take the sum of each inner list
# i.e. [[5,2,6],[5,2,36],[5,2,216],...,[125,512,216],...]
# → [13,43,223,...,853,...]
s # Swap to push the (implicit) input
N> # Push the index + 1
# i.e. 0 → 1
è # Index into the input-list (with automatic wraparound)
# i.e. [526,853] and 1 → 853
å # Check if it's in the list of sums
# i.e. [13,43,223,...,853,...] and 853 → 1
P # Check if it's truthy for both both (and output implicitly)
# i.e. [1,1] → 1
17 2401 -> false
。私はこれにほとんどつまずいています。