4 Replies - 6815 Views - Last Post: 08 July 2013 - 07:21 AM

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Challenge: Longest Bit Sequence

Post icon  Posted 06 July 2013 - 10:28 AM

Challenge: Longest Bit Sequence

Challenge

Write a method that returns the size and position of the longest bit sequence.

Examples
X := 00000000 00000000 00000000 01111100

size:= 5
 pos:= 2

X:=  00000000 00001000 01110100 10001100

size:= 3
 pos:= 12

X:=  01010101 01010101 01010101 01010101
size:=1
 pos:=0 



Edit: Return the right most position, in cases where multiple equal length bit sequences.

Entrants
  • Frameworks required.
  • vb.net submissions are preferred.
  • SourceCode must be in spoilered code tags.
    Spoiler

    If you don't want to reveal your code, then don't submit a submission.
  • If you like you can include a Zip-File of the project / executable.

This post has been edited by AdamSpeight2008: 06 July 2013 - 01:08 PM
Reason for edit:: Updating and correcting wording of challenge.


Is This A Good Question/Topic? 1
  • +

Replies To: Challenge: Longest Bit Sequence

#2 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1940
  • View blog
  • Posts: 4,027
  • Joined: 11-December 07

Re: Challenge: Longest Bit Sequence

Posted 07 July 2013 - 01:01 PM

What is the input datatype? Integer, String, Byte array?
Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: Challenge: Longest Bit Sequence

Posted 07 July 2013 - 02:03 PM

It's open to interpretation, I only specified write a method, not what the method parameter(s).

For mine I'm using Int32 for mine and returning an array of Int32 (containing 2 entries, 1st is size, 2nd is position)

Spoiler

This post has been edited by AdamSpeight2008: 07 July 2013 - 02:50 PM

Was This Post Helpful? 0
  • +
  • -

#4 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1940
  • View blog
  • Posts: 4,027
  • Joined: 11-December 07

Re: Challenge: Longest Bit Sequence

Posted 08 July 2013 - 02:34 AM

OK, well since the input type isn't specified, I'll assume that it is subject to change and define a BitSequence interface. The function has to return 2 values so what is really needed is a class to hold them. I believe the way to write methods that act on interfaces in VB.NET is extension methods.

Here is my solution:

Spoiler


Here is some extra code to make it work, including an implemntation of BitSequence:

Spoiler

Was This Post Helpful? 1
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: Challenge: Longest Bit Sequence

Posted 08 July 2013 - 07:21 AM

cfoley: Nice linear algorithm O(n), came up with a similar on last night.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1