Jump to content

Auto generate a number based on three from an array with rules


bluefrog

Recommended Posts

I am trying to write what should be a short piece of code to generate a 4th number based on three. There is an array with 6 numbers in it, the code needs to take the last three (numerical order) and generate a fourth based on some rules:
 
if last number (array [5]) = the same as array[4] and array[5] is less than 49 then array[5] = array[5] +1
 
if last number (array [5]) = the same as array[4] and array[5] is equal to 49 then array[5] = array[4] -1 IF array[3] is more than 2 less than array[4]
 
eg:
 
Number 1,2,44,45,47,48
 
By these rules the new number can be 49, as although number number 5[4] would be the same as the generated number ([5]-1) it is less than 49 so can be number 6[5] +1 instead.
 
Number 1,2,44,45,46,48
 
By these rules the generated number can be 47, as number 5[4] is more than two away from the last number [5]
 
Number 1,2,44,45,48,49
 
By these rules the generated number would be 47, as the last number [5] is 49 and the second last [4] is the next number in reverse sequence, so cannot go higher than 49 and can't use the next number down, so uses the next number [4] -1
 
 
Here is what I've cobbled together - no laughing please I'm new:
 
<?php



//$lunch = explode(",",$lt_results);
$lunch = array("1","1","1","44","47","48");
sort($lunch);
echo '<br>';
echo $lunch[3];
echo ' - '.$lunch[4];
echo ' - '.$lunch[5];

$last = --$lunch[5];
echo '<br>Last = '.$last;
if ($last == $lunch[4]){
    echo "<br>Ball 5 & pick are the same";
if ($lunch[5]<"49"){
$last = $lunch[5];
echo $last;
}

}  else {
 echo "a is smaller than b";
}
?>

 

Link to comment
Share on other sites

The array is 6 numbers, I want to take the highest three numbers and generate a fourth number based on the highest number (one less). However if the highest number is 48 and the next highest is 47, then the generated number should be 49, but no higher. If the two numbers were 48 and 49 then the number should be lower, so in this case 47 (one less than the next lowest. 

 

Works on numbers 1-49. This is for a lottery website I am setting up (hopefully).

 

Does that make sense? It does in my head lol

Edited by bluefrog
Link to comment
Share on other sites

I'm confused on your explanation. You keep stating you want to use the "highest" three numbers to generate a fourth. But, all of your examples just happen to have the highest (largest) numbers in the last position. So, it is not clear if you are talking about the three numbers with the greatest value or the ones in the last positions of the array. Also, you keep stating the generated value should be based on three numbers, but the logic you have presented only seems to use two.

 

EDIT: Also your explanation of the rules to determine the number are a mess. You state rules when the 4th and 5th numbers are equal to each other, but then give examples where they are not equal to each other. I would think that for a lottery they would never be equal.

Edited by Psycho
Link to comment
Share on other sites

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.