I'm trying to write a function that will check an unknown ammout of cards
for an unknown ammout of possibilitys of a straight.
Code: Select all
<?php
$hand = array(0=>5,1=>7,2=>10,3=>8,4=>6,5=>10,6=>9);
// card_id=>card_value
// all possible straights from a,2,3,4,5 to 10,j,q,k,a
$straights = array( // card_values
array(14,2,3,4,5),
array(2,3,4,5,6),
array(3,4,5,6,7),
array(4,5,6,7,8),
array(5,6,7,8,9),
array(6,7,8,9,10),
array(7,8,9,10,11),
array(8,9,10,11,12),
array(9,10,11,12,13),
array(10,11,12,13,14)
);
// possible straights for this hand
// return arrays of card_ids
$return = array(
array(0,4,1,3,6), // card values 5,6,7,8,9
array(4,1,3,6,2), // card values 6,7,8,9,10
array(4,1,3,6,5) // card values 6,7,8,9,10
);
?>And I just can't seem to figure out how to tackle this problem.
I've tried several different approaches, but all have failed.
I really want to solve this problem on my own,
but I'm just getting too frustrated.
If anyone can just help lead me in the right direction I'd be very happy.