Thread: sequence

  1. #1
    Registered User
    Join Date
    Jan 2006


    please can someone help me with this.

    I want to write a function sequence that returns 1 when a set of 5 cards appear in sequence ; 0 if not.

    I dont understand very well what to do here.

    the sequence is 2,3,4,5,6,7,8,9,10,jack,queen,king, with ace considered as either before 2 or after king as needed

    For example the set of cards( given as follow):

    two of diamonds
    four of clubs
    six of hearts
    three of hearts
    five of spades

    must have sequence =1;

    but for the set of cards:

    two of spades
    king of spades
    ace of clubs
    three of diamonds
    five of hearts

    must have sequence =0

    I give this second example since I do not understand why the sequence is 0 here.

    Can someone explain me what sequence means and give me some suggestions to write the function called sequence??
    Please do not use structure

    Thank you for your time.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Order the cards and you should quickly see one is a sequence and one isn't

    2  two of diamonds
    3  three of hearts
    4  four of clubs
    5  five of spades
    6  six of hearts
    1  ace of clubs (or 14)
    2  two of spades
    3  three of diamonds
    5  five of hearts
    13 king of spades
    The second is not a sequnce becaue the numbers are not contiguous.

    Hopefully you've stored your cards numerically.
    sort the hand lowest to highest
    step through the hand
    if the next card does not equal the current card plus one return 0
    if you made it all the way through the hand return 1
    additional logic to handle the ace
    Last edited by spydoor; 03-30-2006 at 02:08 PM.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    A sequence is a series of values that are all related to one another in some way. What you are looking for is called a straight -- 5 cards in sequence like
    7,8,9,10,J of any suit.

    In your first example, you have a 2,3,4,5,6 which is a series of 5 cards in sequence -- therefore you have a 1.

    In your second example, you have a A,2,3,5,K which is not a series of 5 cards -- therefore you have a 0. The 4 is missing, and in most cases (not all) the Ace is either high or low, not high and low, making Q,K,A,2,3 not a straight. You can create your program either way you'd like though.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading a sequence
    By drag0n69 in forum C Programming
    Replies: 4
    Last Post: 03-17-2008, 04:40 PM
  2. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 12:52 PM
  3. wsprintf and format specifiers
    By incognito in forum Windows Programming
    Replies: 2
    Last Post: 01-03-2004, 10:00 PM
  4. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  5. %i or %d - where is the difference?
    By Sargnagel in forum C Programming
    Replies: 3
    Last Post: 11-12-2002, 03:21 PM