4 Replies - 15728 Views - Last Post: 27 January 2012 - 03:13 PM

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Challenge: Rings (Easy - Intermediate)

Post icon  Posted 18 November 2011 - 08:15 PM

Challenge: Rings

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


Is This A Good Question/Topic? 0
  • +

Replies To: Challenge: Rings (Easy - Intermediate)

#2 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • Posts: 1,688
  • Joined: 13-March 10

Re: Challenge: Rings (Easy - Intermediate)

Posted 19 November 2011 - 09:29 AM

Can we give it a go in C# or only VB.NET is allowed?
Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Challenge: Rings (Easy - Intermediate)

Posted 03 December 2011 - 09:50 PM

My entry using .net4.5 Iterators
Spoiler

Was This Post Helpful? 0
  • +
  • -

#4 Psyguy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 71
  • View blog
  • Posts: 320
  • Joined: 12-January 11

Re: Challenge: Rings (Easy - Intermediate)

Posted 27 January 2012 - 02:56 PM

I am aware this may be a stupid, newby question, but what is "Yield" doing? Is that part of the NuGet package?
Was This Post Helpful? 0
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Challenge: Rings (Easy - Intermediate)

Posted 27 January 2012 - 03:13 PM

View PostPsyguy, on 27 January 2012 - 10:56 PM, said:

I am aware this may be a stupid, newby question, but what is "Yield" doing?


I'm using what is called the Iterator Pattern, yield is use to release (eg yield) control to the calling code.

Quote

Is that part of the NuGet package?

No you'll need either the Async CTP or VS2011 Preview.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1