正の整数の数字で連結されたタイルで連結された長さの B
のブリッジを考えてみましょう。たとえば、 B が41の場合、次のようになります。
----------------------------------------- 12345678910111213141516171819202122232425
今、橋を渡る T の列車を想像してみてください。列車の一番左の点は
X (1-indexed)の位置から始まります。問題の理解を深めるために、 B =
41、T = 10、X = 10 というイベントのスキームを作ってみましょう。電車は等号(
=
)と線を使用して描画されます。
__________ |========| |========| ----------------------------------------- 12345678910111213141516171819202122232425
列車は、各ステップで、それが配置されているユニークなタイルの合計で進むことができます。たとえば、列車が上に立っているタイルは次のとおりです。
[1,0,1,1,1,2,1,3,1,4]
、一意(重複除外)タイルは次のとおりです。 code>
[1、0、2、3、4] で、その合計は 10
です。したがって、列車は 10
タイルで進めることができます。列車の左端の点が最後のタイルを通過するまで、もう一度線を引いてその処理を繰り返す必要があります。
__________ |========| |========| ----------------------------------------- 12345678910111213141516171819202122232425 Sum of unique tiles: 1 + 5 + 6 + 7 + 8 + 9 = 36. The train advances by 36 tiles... __________ |========| |========| ----------------------------------------- 12345678910111213141516171819202122232425 The train obviously crossed the bridge completely, so we should stop now.
内部の人々は退屈なので、電車が毎回進んでいるタイルを数えます。この具体的な例では、 10
と
36
です。すべてを要約すると、列車は橋を渡る前に 46
移動しました。
仕事
Given three positive integers, B (the bridge
length), T (the train length) and
X (the starting position,
1-indexed), your 仕事 is to determine how many tiles
the train has moved until it crossed the bridge following the rules
above.
- You can assume that:
- B is higher than T.
- X is lower than B.
- T is at least 2.
- The train eventually crosses the bridge.
- All our standard rules apply.
- This is code-golf,
so the shortest code in bytes wins!
テストケース
Input ([B, T, X]) -> Output [41, 10, 10] -> 46 [40, 10, 10] -> 46 [30, 4, 16] -> 24 [50, 6, 11] -> 50
最後のテストケースのもう1つの実例:
The bridge is of length 50, the train 6, and the starting position is 11. ______ |====| |====| -------------------------------------------------- 12345678910111213141516171819202122232425262728293 Unique tiles: [0, 1, 2]. Sum: 3. ______ |====| |====| -------------------------------------------------- 12345678910111213141516171819202122232425262728293 Unique tiles: [1, 2, 3, 4]. Sum: 10. ______ |====| |====| -------------------------------------------------- 12345678910111213141516171819202122232425262728293 Unique tiles: [1, 7, 8, 9]. Sum: 25. ______ |====| |====| -------------------------------------------------- 12345678910111213141516171819202122232425262728293 Unique tiles: [9, 3]. Sum: 12. ______ |====| |====| -------------------------------------------------- 12345678910111213141516171819202122232425262728293 Train exists the bridge. Total sum: 3 + 10 + 25 + 12 = 50.
Python 2, 110 105
104 103 100 97 96 bytes
-
氏に5バイトを保存しました。
Xcoder -
氏に感謝してバイトを保存しました。
Xcoder[〜-x:] [:t] にゴルフ[〜-x:x
+〜-t] - バイトを保存しました。
... range(b)))[1:〜〜b]
に変更します。 - 保存された3バイト。
[1:〜〜b] [〜-x:]
から[: - 〜b]
[x:] - 保存された3バイト。
[:-b] [x:]
を[x:-b]
にゴルフ< -
Lynn
に感謝してバイトを保存しました。while
ループをexec
ステートメントに渡します。
b,t,x=input();S=x;exec"x+=sum(set(map(int,''.join(map(str,range(b)))[x:-~b][:t])));"*b;print-S+x