A Ring is the cells that are at a specific distance from the focal position.
For example, the follow 2D array.
0 0 0 0 0 0 1 2 3 0 0 4 5 6 0 0 7 8 9 0 0 0 0 0 0
Focal Position: (2,2)
Ring 0: 5
Ring 1: 1 2 3 4 6 7 8 9
Ring 2: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OK now you have the idea of a ring, you can understand that the idea of a Encircling is all of the rings out to a specific distance.
The ring sequence always begins with the top-left most position, then proceeds in a clockwise direction.
Challenge:
Implement the following interface
The Interface
Public Interface IRings(Of T) ''' <summary> ''' Get a particular ring of elements from a 2D array. ''' </summary> ''' <param name="Source">The 2D array to use.</param> ''' <param name="x">x position to start from.</param> ''' <param name="y">y position to start from.</param> ''' <param name="OutOfBounds">What to use of the out of bounds value?</param> ''' <param name="Ring">Which ring to return (0 - Inner Most)</param> ''' <returns>An IEnumerable</returns> ''' <remarks>Ring must not be negative</remarks> Function GetRing(ByVal Source(,) As T, x As Integer, y As Integer, ByVal Ring As Integer, ByVal OutOfBounds As T) As IEnumerable(Of T) ''' <summary> ''' Get all of the ring of elements surrounding a particular element of a 2D array. ''' </summary> ''' <param name="Source">The 2D array to use.</param> ''' <param name="x">x position to start from.</param> ''' <param name="y">y position to start from.</param> ''' <param name="Rings">Number of rings to return</param> ''' <param name="OutOfBounds">What to use for the out of bounds value?</param> ''' <param name="IncludeStartingPosition">Should the element at the starting position be included (eg Ring 0)? (Default is False)</param> ''' <returns>Returns an IEnumerable(Of IEnumerable(Of T)) containing all the elements.</returns> ''' <remarks>Rings must not be negative</remarks> Function GetEncirling(ByVal Source(,) As T, x As Integer, y As Integer, ByVal Rings As Integer, ByVal OutOfBounds As T, Optional IncludeStartingPosition As Boolean = False) As IEnumerable(Of IEnumerable(Of T)) End Interface
To help you with this challenge you can obtain the Interface from the following NuGet Package: DIC Challenge: Rings Interface
This post has been edited by AdamSpeight2008: 18 November 2011 - 08:42 PM