Jump to content

Recommended Posts

Okay, users can select numbers:

 

0000 to 9999

 

I already finished to check inputs serverside.

 

 

The problem is let's say I have:

 

1413,1812,2325,2326,2623,3236,3738,3932,5156,6169

 

 

 

Now,  that is USER JOE.  If USER Joe picks those numbers, I will need to find out the following:

 

 

*Match 4 numbers in the correct order win <b>100%</b> of the jackpot. (Odds: 1 in 10,000)<br>
*Match 2 numbers in the correct order win <b>40%</b> of the jackpot. (Odds: 1 in 833)<br>
*Match 4 numbers in the wrong order win <b>20%</b> of the jackpot. (Odds: 1 in 417)<br>

 

And the correct number, let's say is "8521";

 

 

 

So what kind of php functions should i be dealing with here? I will need to foreach seperate them

 

$numbers = "1413,1812,2325,2326,2623,3236,3738,3932,5156,6169";

foreach(explode(',', $numbers) as $num_set)
{


//Need to find how to match my 8521 with the numbers here



}

 

Long story short, I will be extracting this data from my MYSQL table called "daily4_tickets" and it will have rows of data for all my users with their chosen numbers.  Hope I am going in the right place,

 

I know i need to use some type of array_key matching, need some help to move me into the right direction,

 

thank you

 

Link to comment
https://forums.phpfreaks.com/topic/268461-help-with-my-daily-4-lottery-game/
Share on other sites

<?
class Number
{
private $number;
private $numbers;

function __construct($nr)
{
   $this -> number = strval($nr);
   $this -> numbers = array();
   $this -> numbers[] = $nr[0];
   $this -> numbers[] = $nr[1];
   $this -> numbers[] = $nr[2];
   $this -> numbers[] = $nr[3];
}

function Get($index)
{
  return isset($this -> numbers[$index]) ? $this -> numbers[$index] : null;
}

function Get2()
{
  $array = array();
  $array[] = $this -> Get(0) . $this -> Get(1);
  $array[] = $this -> Get(1) . $this -> Get(2);
  $array[] = $this -> Get(2) . $this -> Get(3);
  return $array;
}

function GetAllVariations()
{
  $array = array();
  for ($i1 = 0; $i1 < 4 ; $i1++)
   for ($i2 = 0; $i2 < 4 ; $i2++)
    for ($i3 = 0; $i3 < 4 ; $i3++)
     for ($i4 = 0; $i4 < 4 ; $i4++)
     {
       $array[] = $this -> Get($i1) . $this -> Get($i2) . $this -> Get($i3) . $this -> Get($i4);
     }
  return $array;
}
}

$numbers = "8512,1812,2325,2326,2623,3236,3738,3932,5256,6169";
$win = 8521;
$numbers = explode(',', $numbers);
foreach($numbers as $num)
{
#check 100%
if ($num == $win) 
  { 
     echo '*Match 4 numbers in the correct order win <b>100%</b> of the jackpot. (Odds: 1 in 10,000)<br>';
     continue;
  }
#check 2 numbers in correct :

$nr = new Number($num);
foreach ($nr->Get2() as $cur)
{
  if (strpos($win,$cur) !== false)
  {
   echo "*Match 2 numbers in the correct order win <b>40%</b> of the jackpot. (Odds: 1 in 833)<br>";
  }
}
#4 in wrong: 
if (in_array( $win, $nr -> GetAllVariations()))  echo '*Match 4 numbers in the wrong order win <b>20%</b> of the jackpot. (Odds: 1 in 417)<br>';
}

Hey, i never really touched php classes/etc so it's honestly like a whole new ball game, hehe.

 

I really look at that code like a new life cuz I don't really understand the top half of it all, im more of a old fashion php kid, so i apologize.

 

guess it's time to learn though right?

 

 

Thanks for it and i'll use it to the best of my knowledge, lol

 

im currently extracting this:

 

 

$query = $db->query("SELECT l.*,m.id,m.username,m.star FROM daily4_tickets as l
							LEFT JOIN users m ON (m.id=l.user_id) ORDER BY date ASC") or error('Unable to send the message.', __FILE__, __LINE__, $db->error());

$winning_number = 1992;

			while($dailycheck = $db->fetch_assoc($query)) {

$tickets[$dailycheck['user_id']] = explode(',', $dailycheck['numbers']);



		var_dump($tickets);
		//Check if a user matched a Ticket
		if (in_array(1992, $tickets[$dailycheck['user_id']])) {
		$winninguser_ids[] = $dailycheck['user_id'];
		}

//Check if a user matched 2 numbers in order
//???

//Check if a user matched all 4 numbers but not in order??
//??? 

}
echo implode(",", $winninguser_ids);

 

 

I will incorporate your code or try too once iget around with it,

 

my var_dump is

array
  271 => 
    array
      0 => string '1413' (length=4)
      1 => string '1812' (length=4)
      2 => string '2325' (length=4)
      3 => string '2326' (length=4)
      4 => string '2623' (length=4)
      5 => string '3236' (length=4)
      6 => string '3738' (length=4)
      7 => string '3932' (length=4)
      8 => string '5156' (length=4)
      9 => string '6169' (length=4)
      10 => string '6264' (length=4)
      11 => string '7873' (length=4)
      12 => string '8586' (length=4)
      13 => string '9497' (length=4)
      14 => string '1992' (length=4)
array
  271 => 
    array
      0 => string '1312' (length=4)
      1 => string '2527' (length=4)
      2 => string '5451' (length=4)
array
  271 => 
    array
      0 => string '7071' (length=4)
      1 => string '8184' (length=4)
array
  271 => 
    array
      0 => string '2528' (length=4)
      1 => string '8089' (length=4)
array
  271 => 
    array
      0 => string '6789' (length=4)
array
  271 => 
    array
      0 => string '6789' (length=4)
      1 => string '8987' (length=4)
array
  271 => 
    array
      0 => string '6789' (length=4)
array
  271 => 
    array
      0 => string '7654' (length=4)
array
  271 => 
    array
      0 => string '7654' (length=4)
  106 => 
    array
      0 => string '2421' (length=4)
      1 => string '1992' (length=4)
271,106

 

so im kinda on the other road as your script atm, but like I said, i will save it and use it once I get setted in on php CLASSES and stuff.

 

right now, I just need to know how to differentiate between matching only 2 numbers in order and 4 all correct but in the wrong order.. hehe

$lottery_numbers = array(1413,1812,2325,2326,2623,3236,3738,3932,5156,6169);
$user_numbers = array(2326,3236);

$matches = array_filter($lottery_numbers, function($lottery_number) use ($user_numbers) {
    return in_array($lottery_number, $user_numbers);
});

switch (count($matches)) {
    case 2:
        if (is_consec($matches)) {
            // consecutive
        } else {
            // not
        }
        break;
    case 4:
        if (is_consec($matches)) {
            // consecutive
        } else {
            // not
        }
        break;
    default:
        // nada!
        break;
}

function is_consec($array) {
    $lastKey = null;
    foreach ($array as $key => $value) {
        if (!is_int($key)) {
            if ($lastKey !== null) {
                return false;
            }
            continue;
        }
        if ($lastKey === null) {
            $lastKey = $key;
        } else if (abs($key - $lastKey) !== 1) {
            return false;
        }
    }
    return true;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.