Excel VBA、 59 46バイト
ゴルフ
範囲からの入力としてスペース()で区切られた配列文字列を受け取り[A1]
、開始リストの1ベースのインデックスの数値モジュラスをVBEイミディエイトウィンドウに出力する匿名VBEイミディエイトウィンドウ関数
For Each n In Split([A1]):i=i+1:?n Mod i;:Next
入出力:
[A1]="10 9 8 7 6 5 4 3 2 1" ''# or manually set the value
For Each n In Split([A1]):i=i+1:?n Mod i;:Next
0 1 2 3 1 5 4 3 2 1
古いSub
ルーチンバージョン
入力を渡された配列として受け取り、VBEイミディエイトウィンドウに出力するサブルーチン。
Sub m(n)
For Each a In n
i=i+1
Debug.?a Mod i;
Next
End Sub
入力/出力:
m Array(10,9,8,7,6,5,4,3,2,1)
0 1 2 3 1 5 4 3 2 1
非ゴルフ
Option Private Module
Option Compare Binary
Option Explicit
Option Base 0 ''# apparently Option Base 1 does not work with ParamArrays
Public Sub modIndex(ParamArray n() As Variant)
Dim index As Integer
For index = LBound(n) To UBound(n)
Debug.Print n(index) Mod (index + 1);
Next index
End Sub
入出力:
Call modIndex(10,9,8,7,6,5,4,3,2,1)
0 1 2 3 1 5 4 3 2 1