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.
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
The second is not a sequnce becaue the numbers are not contiguous.
1 ace of clubs (or 14)
2 two of spades
3 three of diamonds
5 five of hearts
13 king of spades
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
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.