Skip to main content
added 78 characters in body
Source Link
Taylor Raine
  • 8.7k
  • 2
  • 27
  • 51

#Excel VBA, 59 46 Bytes

###Golfed

Anonymous VBE Immediate window funtion that takes a space ( ) delimited array string as input from cellrange [A1] and outputsoutput the numbers modulus their 1-based index in the starting list to the VBE immediate window

For Each n In Split([A1]):i=i+1:?n Mod i;:Next

Input / Output:

[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 

###Old Subroutine version

Subroutine that takes input as a passed array and outouts to the VBE immediate window.

Sub m(n)
For Each a In n
i=i+1
Debug.?a Mod i;
Next
End Sub

Input / Ouput:

m Array(10,9,8,7,6,5,4,3,2,1)
 0  1  2  3  1  5  4  3  2  1 

###Ungolfed

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

Input / Output:

Call modIndex(10,9,8,7,6,5,4,3,2,1)
 0  1  2  3  1  5  4  3  2  1 

#Excel VBA, 59 46 Bytes

###Golfed

Anonymous VBE Immediate window funtion that takes a space delimited array string as input from cell [A1] and outputs to the VBE immediate window

For Each n In Split([A1]):i=i+1:?n Mod i;:Next

Input / Output:

[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 

###Old Subroutine version

Subroutine that takes input as a passed array and outouts to the VBE immediate window.

Sub m(n)
For Each a In n
i=i+1
Debug.?a Mod i;
Next
End Sub

Input / Ouput:

m Array(10,9,8,7,6,5,4,3,2,1)
 0  1  2  3  1  5  4  3  2  1 

###Ungolfed

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

Input / Output:

Call modIndex(10,9,8,7,6,5,4,3,2,1)
 0  1  2  3  1  5  4  3  2  1 

#Excel VBA, 59 46 Bytes

###Golfed

Anonymous VBE Immediate window funtion that takes a space ( ) delimited array string as input from range [A1] and output the numbers modulus their 1-based index in the starting list to the VBE immediate window

For Each n In Split([A1]):i=i+1:?n Mod i;:Next

Input / Output:

[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 

###Old Subroutine version

Subroutine that takes input as a passed array and outouts to the VBE immediate window.

Sub m(n)
For Each a In n
i=i+1
Debug.?a Mod i;
Next
End Sub

Input / Ouput:

m Array(10,9,8,7,6,5,4,3,2,1)
 0  1  2  3  1  5  4  3  2  1 

###Ungolfed

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

Input / Output:

Call modIndex(10,9,8,7,6,5,4,3,2,1)
 0  1  2  3  1  5  4  3  2  1 
Source Link
Taylor Raine
  • 8.7k
  • 2
  • 27
  • 51

#Excel VBA, 59 46 Bytes

###Golfed

Anonymous VBE Immediate window funtion that takes a space delimited array string as input from cell [A1] and outputs to the VBE immediate window

For Each n In Split([A1]):i=i+1:?n Mod i;:Next

Input / Output:

[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 

###Old Subroutine version

Subroutine that takes input as a passed array and outouts to the VBE immediate window.

Sub m(n)
For Each a In n
i=i+1
Debug.?a Mod i;
Next
End Sub

Input / Ouput:

m Array(10,9,8,7,6,5,4,3,2,1)
 0  1  2  3  1  5  4  3  2  1 

###Ungolfed

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

Input / Output:

Call modIndex(10,9,8,7,6,5,4,3,2,1)
 0  1  2  3  1  5  4  3  2  1