• Resolved herculesnetwork

    (@herculesnetwork)


    Make a rand with digits and do not allow ‘echo’ with repeated results up to 7 digits inside each key

    
    $getoutput15numb = array(1,2,3,4,5,6,7,8,9....119,120);
    

    A large array of one to 120 numbers, will make rand to get 15 numbers, Being another matrix, I will manually put the numbers already returned before, and this rand will start again every time it counts sequences of 7 digits in any of the sequences obtained earlier.

    
    $Sequencespreviouslyobtained = array("1,9,8,2,6,4,8,2,1,7,9,2,1,5,7","4,5,8,7,4,5,2,1,4,5,6,2,1,4,5,","4,8,1,3...","","",);
    

    A condition, not to accept values with 7 previously repeated sequences of up to 7 digits in the above arrays: Are not only 7 first, but 7 digits all over the key: Let’s use as an example, the first key, if the mt_rand, return as a result, one of these sequences:

    
    1,9,8,2,6,4,8
    or this:
    8,2,6,4,8,2,1
    or this:
    4,8,2,1,7,9,2
    the mt_rand run again.
    

    Until processing an unedited result up to 6 sequential digits (the objective is to have at most 6 sequences that have happened before, the more unedited the results the better). So: echo

    Would a better regex expression be applicable?

Viewing 10 replies - 31 through 40 (of 40 total)
  • Thread Starter herculesnetwork

    (@herculesnetwork)

    …. Then I will check the stupid directives that is in my local php.ini srsrsr
    I made your code run on a remote php7 vps ..

    
    $numbers = range(1, 300);
    shuffle($numbers);
    function get_rand_array($min, $max, $quantity) {
        $numbers = range($min, $max);
        $count = random_int( 1, 300 );
        for ($x=0; $x<=$count; $x++) {
            shuffle( $numbers );
        }
        return  array_slice( $numbers, random_int( 0, $max - $quantity ), $quantity );
    }
    var_dump (implode(array_slice( $numbers, random_int( 0, $max - $quantity ), $quantity ))); 
    

    Sorry for the stupid mistake… my friend, I learned a lot from this topic! And I hope this topic helps many people wanting to solve things with random numbers… Thaankkkssss.

    I have a doubt @bcworkz, about wordpress cron, how to make a plugin fire at the scheduled interval, I have taken a look, and found it relatively simple to just make a script run, but it is not just a script run, I want to run third party plugins with The filled field .. for example, a plugin that searches the internet for images. And import creating posts, then this plugin has a page in the plugin option with a search field and has a search button, and another button to import. The cron action would have to do that !! I fill out, and do the search with a field already filled in by me and the action of those two buttons, doing this, I would automate many things here! I’ve never done anything like it! But I’ll ask this later, you’ve been helping me aaaaalooooooot in at least 15 days I’m going to open a topic and this does not even have urgency now. I got a lot of things at my work, Since the 2nd of april, I consider this my project concluded, but this, the cron, would be the cake cherry 😀

    Thaaaaaaaanksssssssssss!!!

    Moderator bcworkz

    (@bcworkz)

    Always happy to help 🙂
    No worries about PHP5, I can never remember the configurations of the servers I access. What’s important is the problem is solved! I imagine having access to Apache can be useful. You might consider upgrading the PHP there 😉

    What’s odd about WP Cron is it’s not a true Cron Job implementation. It is dependent on visitation to WP to work (people, bots, hackers, any WP requests) Thus, depending traffic levels, the job may not execute on time. On low traffic sites, or if you need better time accuracy, a true Cron Job may need to be added, meaning you would need WP-CLI. Some people have setup a monitoring service like uptimerobot.com to ensure regular visitation instead of adding a Cron Job.

    I’ll be watching for your next topic 🙂

    Thread Starter herculesnetwork

    (@herculesnetwork)

    hi again! :-$ I had a curiosity about how my stepfather could identify that he needed to reject 7 … reject at least 7 repeated numerical sequences in the previous results in time to generate your new numbers for your application on one of your pages from your wordpress blog . He told me: I spent weeks analyzing the list of naked eye .. I said: Ow, by the beard of the gods of asgard!! How accurate he could have gotten with it! 2,000 previous results! So, that software I’ve already changed in a number of ways, So that software bcworkz condition can easily be changed to any acceptable limit rule, from 7 to any number … so I thought, bcworkz’s condition is ready to make a foreach for the previous results, and instead of echoing a new sequence, I can replicate it. BCworkZ’s condition only say a sentence stating the maximum size of a duplicate, duplicate:

    Echo ‘in these previous results, it was detected that the size of the largest duplicate portion is’ . $Notice . ‘Digits’;

    Output:
    In these previous results, it was detected that the size of the largest duplicate portion is 8 digits.

    Where $Notice is just the number, the result of the analyze of the condition. In this condition, it will analyze the size of the duplicate section, as we do not have to define numbers, only to get the size of that match, in a simple number returned, I think it is simpler.

    I think this can be very simple and fast:

    I think that we need to use array_count_values

    
    $array = array('apple', 'orange', 'pear', 'banana', 'apple',
    'pear', 'kiwi', 'kiwi', 'kiwi');
    
    print_r(array_count_values($array));
    will output
    
    Array
    (
       [apple] => 2
       [orange] => 1
       [pear] => 2
       etc...
    )
    
    Thread Starter herculesnetwork

    (@herculesnetwork)

    Of course, in order not to leave a screen print with a giant list of duplicate numbers, it should display the largest output sequence slice.

    Editing, now that I’ve noticed, I’m using a wrong function because it parses the data in an array, and I’m working with multiple arrays!

    Here is this case: this case

    Or say how many numbers are duplicated in the largest duplicate snippet, or simply print that largest duplicate snippet, then count how many are duplicated using our own srsr fingers

    
    <?php
    header('Content-Type: text/html; charset=utf-8');
    echo 'This is just for us to figure out, what is the size of the greatest duplication of stretches between the previous sequences'.'<br>';
    
    // This values will always be updated manually, every time I make use of a result, I will insert here for never I use anything with up to 7 consecutive digits in any stretch, slice of these results
    $previous_results_manually_inserted = array(
     array('12','21','34','1','51','87','42','49','37','119','101','7','111','17','11','19','2','15','6'),
     array('3','5','1','18','61','75','92','84','36','81','2','07','90','2','71','17','08','51','37'),
     array('81','72','91','22','75','87','33','97','120','11','17','65','44','73','27','30','41','74','88'),
    );
    
    foreach ($previous_results_manually_inserted as $value)
    {
      $How_many_duplicates = array_count_values($previous_results_manually_inserted[$value]);
            $How_many_duplicates[$value]++;
    }
    print_r($How_many_duplicates);
    

    ou

    How to count how many duplicate keys are in array?

    Thread Starter herculesnetwork

    (@herculesnetwork)

    So @bcworkz .. It’s not exactly to just count how many keys are duplicated, but to tell you the largest sequence of duplicate keys, I think your condition is “ready” for that. In case, use its condition, not to cut into 13 slices to analyze these slices of 7 numbers, but to analyze the whole stretch from the beginning to the end of each result inserted manually, and print the largest duplicate slice. Our software is perfect, analyze what it used to ask for this software, it is very inaccurate, so you can lose the benefits of our flexible software. Can be accurately aided for the right number of unique results, through this other software made only with its condition, and the big array of manual inserted results.

    
    echo 'in these previous results, it was detected that the size of the largest duplicate portion is' . $Notice . 'digits.';
    

    output:

    in these previous results, it was detected that the size of the largest duplicate portion is 5 digits.

    Or simply print the largest duplicate slice, for get this output:

    12,78,1,95,54

    With the result of this algorithm, I will be able to change the number 7, to a more precise number in our application, so that it is truly beneficial. He gave me the number 7 by hand conference!

    Moderator bcworkz

    (@bcworkz)

    If I understand correctly, it is not as easy as you think. I believe you are looking for the largest sequence of numbers that repeat at least once in an array of sequence arrays. It’s certainly something suited for computer processing. Analysis by eye is fraught with potential errors.

    First let’s be sure we are using the right terminology. It’s not possible to have repeating keys in the same array. Do you mean repeating values? Or repeating keys in other arrays? Example indexed array print_r() output:

    Array
    (
        [0] => value for key/index 0
        [1] => value for key/index 1
        [2] => value for key/index 2
    )

    And for associative arrays:

    Array
    (
       [key-0] => value for key-0
       [key-1] => value for key-1
       [key-2] => value for key-2
    )

    Values in the same array may repeat, keys or indexes cannot.

    Finding repeating single elements can simply be done with in_array(). Repeating keys from different arrays is similarly easy with array_keys(). Neither really helps us since we are concerned with sequences, not single values.

    The process of identifying repeating elements is remarkably similar to the .zip compression algorithm (and likely others, I’m only familiar with .zip, or more generically the Lempel–Ziv lossless compression) A stream of data is examined for repeating elements, beginning with repeating pairs. Each pair found is assigned a token to represent it. The process is repeated for 3 values, then 4, etc. In some cases a repeating sequence could be comprised of new data and previously determined tokens.

    It may occur there are repeating elements that are very long, which is replaced by a single token. The resulting compressed token stream is typically much shorter than the original data. They way the data is organized makes decompression a virtual reversal of the process.

    Of course we do not need to keep track of smaller tokens, nor what they represent, nor the need to work in reverse, so the process is significantly simpler.

    I’m unsure if it’s better to use array_slice() to find sequences or to implode arrays in order to use preg_match() or strpos() to locate matches. Since arrays can be evaluated for equivalence just like strings can, I’m inclined to use array_slice(). This is a valid equivalence and evaluates to true: array(1,2,3) == array(1,2,3)

    The basic approach would be to take array slices out of the main data where slice length is anywhere from 2 to the maximum sub-array length. For each array slice, search through the main data looking for a match. For each match, record the slice length. After going through every possible array slice of every possible length, go through the recorded lengths to find the largest count.

    This does not tell us what the longest sequence is, only that at least two of that length exist somewhere in the main data. That need can be accommodated, but first lets look at possible shortcuts because going through every possible array is going to be very time consuming.

    I think the best shortcut is to work backwards from the longest possible array slice. As soon as any match is found, we know that is the longest, because we were already unable to find any longer matches. We also know what that sequence is since we just matched it. It does not tell us if there are any other matches of the same length or if there is more than one match to the sequence. There could be 5 sequences matching, we only found the first one encountered.

    Of course we could complete the search at the current length to find more matches of the same length if need be. At least we still do not need to search for shorter sequences. We must also ensure we do not try to slice an array farther along than $maximum – $length, or else the slice will be incomplete. I’m not seeing any other shortcuts right now.

    Because finite sizes are easier to think about than variables, I’m going to start by defining our main data as an array of 9 sub-arrays (indexed 0-8), each sub-array has a sequence of 19 numbers, indexed 0-18. This is assigned to $haystack. You can convert the finite sizes to variable sizes easily enough. The metaphor is searching for needles in a haystack. I think the basic algorithm would be like this (in pseudocode):

    $needles = $haystack // the needles and haystack are the same. Different names for less confusion
    set $flag to true    //a match will change it to false
    while $flag is true {
      for $size = 19 to 2 { // length of needle and haystack sub-part
    
        // get all possible needles
        for $sub = 0 to 8 {
          $source = $needles[$sub]  //slice within each sub-array
          for $start = 0 to 19-$size {
            $needle = array slice $source at $start where length is $size
    
            // get all possible haystack sub-parts to compare with needle
            for $sub2 = 0 to 8 {
              $haypart = $haystack[$sub2] //check within each sub-array
              for $start2 = 0 to 19-$size {
                // do not compare $needle and $subpart when they are from the same source
                if ($sub == $sub2 && $start == $start2) skip the rest of this iteration and continue with next
                $subpart = array slice $haypart at $start2 where length is $size
    
                if ($needle == $subpart) then {
    
                  // a match was found!
                  set $flag to false
                  output: A sequence of $size numbers has at least one duplicate
                  print_r: [{implode ', ', $needle}] 
                  break 5 //stop processing and break out of all loops 
                }
              }
            }
          }
        }
      }
    }

    The loop counters may need adjustment. The first pass through when $size == 19 is just supposed to compare each sub-array against all the rest, so each loop would run only once. Using pseudo code numbers, the first pass has loops doing from 0 to 0, which I think means nothing is run, but 0 to 1 is two passes, also incorrect. But in PHP we would have for ($n=0; $n<=0; $n++) which should give us one pass, so maybe it’s OK.

    When $size == 18, each sub-array offers two possible slices. When 17, 3 slices, etc. This is all completely untested. You should do some careful checking at various points in the code to be sure the algorithm is working as it should be. I presented the algorithm as pseudocode because you should be able to work out for yourself proper coding syntax based on conversational phrases.

    Thread Starter herculesnetwork

    (@herculesnetwork)

    This new software is just to check the data of the large array with those phrases entered manually, so we do not have to worry about dozens of duplicates, but you got it very well, check each key of all the sequences entered manually in the large array , Compare them to each other, and see which is the largest sequence and print this sequence. As your condition has already checked the array with foreach, I thought it was simpler, yes, I’ll analyze your answer and sorry for my succesful posts, I’m very anxious and curious at times, my stepfather is not paying much attention to this second part , But I really want to understand this and see how it works. Thank you again.

    Thread Starter herculesnetwork

    (@herculesnetwork)

    hey my friend. I must really tell you, that this thing is a lot more complex than I was imagining, about in_array () and array_keys () and array_count_values ​​I realized yesterday that it really would not be applicable (but I had Flooded here from posts by anxiety :-$ ), I was thinking wrong, and it’s like you said: we need to compare the sequence of keys, among the numerical values ​​of the array, I’ve never seen such a need before! Our software is already being used by my stepfather and he is already happy , Even though I explained that he certainly did not make a request with exact data what he really needs, he asked for the software, he did not give us precise rules, moral of the story, I did not think he does not need this new software, but I looked For this case, I note that the size of its complexity and how curious it is is proportional to the size of the ultility it can be … analyzing data between values ​​already entered into the system. For me!!
    [SOLVED]

    
    $arrs = [
     ['12','21','34','1','51','87','42','49','37','119','101','7','111','17','11','19','2','15','6'],
     ['3','5','1','18','61','75','92','84','36','81','2','07','90','2','71','17','08','51','37'],
     ['81','75','92','84','36','81','2','07','90','2','17','65','44','73','27','30','41','74','88'],
    ];
    $sequence = [];
    foreach($arrs as $offset => $item){
        $sarr = array_slice($arrs , $offset+1);
        $count = count($item);
        foreach($sarr as $arr){
            $str = join(',',$arr);
            for($a = 0;$a<$count;$a++){
                for($b = 1;$b<$count;$b++){
                    $needle = join(',',array_slice($item , $a , ($a + $b > $count ? $count : $b)));
                    if(strpos($str,$needle) !== false){
                        $sequence[(substr_count($needle,','))] = $needle;
                    }
                }
            }
        }
    }
    echo array_pop($sequence).PHP_EOL;
    

    [/SOLVED]
    It’s not my code, but follow your idea a little, and I see your previous code, when you have a while, I’ll study this code, to understand it well, because it’s really interesting, I already imagine some case where this code will help!

    THANK YOU So Much @bcworkz

    Moderator bcworkz

    (@bcworkz)

    You are welcome my friend.

    Another good lesson here is clients, whether friends, family, or paying… (not that friends and family couldn’t pay. Doing business with friends and family is often a bad idea. Often better to do it for free out of love or not at all)…they will never give you adequate detail about their needs. It’s your job to ask the right questions so you understand their goals and can provide a good solution even if it’s not what they asked for. This is all the more difficult because most people do not respond well to being asked too many pesky little detailed questions about their request. Questions they probably never thought about and probably don’t even understand the implications.

    You need to act as interpreter to develop the solution they really need regardless of what they specifically asked for. Even after many years of experience, I’m still learning how to do this!

    Thread Starter herculesnetwork

    (@herculesnetwork)

    Yes my friend, it’s that way !! And hey, he’s very lucky! He checked 10 percent of the gigantic array’s numbers to assume he needed the maximum of 7 repeated numbers! And yes, our code served him! Because as I redefined this algorithm above, it printed the largest duplicate sequence … and the output was 6 tens !!! How lucky of him !! This time code was to know if the software would need adjustment, and do not need it, now it is also essential to adjust in the future, if a new result, present a duplicity greater than 6, then change from 7 to the new number !! Thanks @bcworks !! You are awesome!

Viewing 10 replies - 31 through 40 (of 40 total)
  • The topic ‘Make a rand with digits and do not allow ‘echo’ with repeated results up to 7 di’ is closed to new replies.