Skip to content

Instantly share code, notes, and snippets.

@VarunBatraIT
Last active December 27, 2021 11:40
Show Gist options
  • Save VarunBatraIT/37e96c0e33b6be4bc21db1d987b25a76 to your computer and use it in GitHub Desktop.
Save VarunBatraIT/37e96c0e33b6be4bc21db1d987b25a76 to your computer and use it in GitHub Desktop.
PHP Assignment SpiceGems

Collect all the under roots (Square Root: For instance 4 under root is 2) of all the positive integers between 1 to 100000 which are prime numbers in an array. Randomize the order of an array such that only ONE random triplet is in original order with exact same indices.

For instance, if input would have been 50, under root array would have been as following in ascending order:

$input = 50;
$ordered_output = [1, 2, 3, 5, 7];

and after randomize output would have been any one of the following but random everytime:

// 1,2,3 are in same order and indexes
$random_output = [1, 2, 3, 7, 5]
//or
// 3,5,7 are in same order and indexes
$random_output = [2, 1, 3, 5, 7]
//or
// 2,3,5 are in same order and indexes
$random_output = [7, 2, 3, 5, 1]

Which are an acceptable random arrays of prime numbers under root between 1 and 50 where tuplet is in order with the same index as that of ascending. 1, 2, 3 and 3, 5, 7

Where as following are UNACCEPTABLE [5, 1, 2, 3, 7] as indexes of 1, 2, 3 are not original

$wrong_indices = [5, 1, 2, 3, 7];

Since originally index of 1 was 0, now it is 1. (Moved by 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment