|
-
Feb 8th, 2010, 10:53 PM
#1
Thread Starter
New Member
Ordering Integers, Small -> Big + knowing length of streak
Hi everyone, first time posting here.
I was wondering if someone could help me out w/ this little problem I'm having.
card1
card2
card3
card4
card5
card6
card7
are my integers and they range from 2 to 14 (yes, we're dealing w/ cards 2 -> Ace)
what I would like to do is order them from smallest to largest and find out what the longest streak is.
for example:
With the 7 cards being: 2, 2, 3, 4, 7, 9, 13
2, 3, 4 would be the longest streak, so the answer would be 3. I also need to know where the streak starts and where it ends. In this example, 2 is the start, 4 is the end.
Thanks alot for your help!
Last edited by MuscleShark88; Feb 9th, 2010 at 01:15 AM.
-
Feb 9th, 2010, 09:07 AM
#2
Re: Ordering Integers, Small -> Big + knowing length of streak
Welcome to the forums.
You will want a sorting algorithm. Here are several submitted by Ellis Dee.
Regarding your streak, maybe a simple loop. Start at 2nd sorted card, and see if it is +1 from the previous. If so, keep checking and keep count. If another streak is found and is longer, keep that count and where it started. All this is done within a single For:Next loop.
Edited: You don't need to keep track of the end of the streak. The end = streakStart + streakLen - 1
Last edited by LaVolpe; Feb 9th, 2010 at 09:16 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|