1

I am making the player ranking system. Every player finishes the game in minimum time. To make the system, I have generated a random array of 100 numbers. Now I want to have the second array of let's say 5 elements. Which will be the random array also and I want to rand these five elements which may not be in that array of may be in between the consecutive numbers.

array([48425.41897186, 49791.74686595, 50637.6692345 , 51287.48403098,
   51799.4937794 , 52261.37861867, 52656.14894694, 53016.05001912,
   53319.51413285, 53613.1572321 , 53884.85189549, 54133.26576367,
   54369.24268884, 54602.45429572, 54824.0431121 , 55028.76273135,
   55225.52231596, 55422.08148893, 55614.70856782, 55790.25574904,
   55966.69616331, 56130.87364057, 56296.84241876, 56449.88078966,
   56608.27073321, 56765.40364215, 56921.28268835, 57077.1635885 ,
   57222.81105772, 57368.09444527, 57504.20581419, 57642.81117631,
   57783.76446837, 57921.46851864, 58065.22310307, 58200.13860351,
   58325.12910768, 58462.47722569, 58595.54625497, 58726.54371695,
   58851.6376891 , 58985.00769808, 59119.15752146, 59248.91267942,
   59377.08378369, 59504.93791765, 59633.1467344 , 59763.72088164,
   59886.39027783, 60019.02739838, 60147.06211421, 60278.91505155,
   60400.41707501, 60526.78944757, 60651.09681352, 60773.59377531,
   60903.3130914 , 61035.07430937, 61161.05200311, 61286.28399277,
   61419.73128784, 61548.88168331, 61678.23125819, 61817.95792148,
   61948.2306147 , 62091.7046512 , 62226.53485998, 62367.68337618,
   62504.82268713, 62644.56529322, 62791.4105829 , 62937.55206985,
   63094.47498604, 63249.99101185, 63405.82395567, 63558.83126992,
   63730.35479375, 63893.18410211, 64063.05247982, 64234.61509263,
   64418.23843848, 64606.76243476, 64800.75451622, 65009.26210584,
   65219.78865272, 65435.37137585, 65684.50945914, 65933.51808688,
   66192.20550111, 66475.37401097, 66770.66277284, 67101.61275613,
   67448.96286764, 67844.22369744, 68294.14575387, 68836.7503846 ,
   69484.01436583, 70336.85011311, 71689.84667803, 82113.06510423])

Here is the array that I want to rank.

    dataPoit_list.add(40425.00);
    dataPoit_list.add(53590.00);
    dataPoit_list.add(54622.00);
    dataPoit_list.add(56802.00);
    dataPoit_list.add(50664.00);
    dataPoit_list.add(58086.00);
    dataPoit_list.add(59624.00);
    dataPoit_list.add(52641.00);

The first element is not in the array. It means the player finished the race really fast. The second element is between two numbers. Is there any ranking function in java? if now how can I make this ranking system? It's a very common question but I could not find a single solution here.

Irfan Yaqub
  • 140
  • 10

1 Answers1

1

First you should convert your array to list,because with an array it's nearly impossible to solve this problem. There is the solution

List<Double> array = new ArrayList();
        Collections.addAll(array = new ArrayList<Double>(), 48425.41897186, 49791.74686595, 50637.6692345, 51287.48403098,
                51799.4937794, 52261.37861867, 52656.14894694, 53016.05001912,
                53319.51413285, 53613.1572321, 53884.85189549, 54133.26576367,
                54369.24268884, 54602.45429572, 54824.0431121, 55028.76273135,
                55225.52231596, 55422.08148893, 55614.70856782, 55790.25574904,
                55966.69616331, 56130.87364057, 56296.84241876, 56449.88078966,
                56608.27073321, 56765.40364215, 56921.28268835, 57077.1635885,
                57222.81105772, 57368.09444527, 57504.20581419, 57642.81117631,
                57783.76446837, 57921.46851864, 58065.22310307, 58200.13860351,
                58325.12910768, 58462.47722569, 58595.54625497, 58726.54371695,
                58851.6376891, 58985.00769808, 59119.15752146, 59248.91267942,
                59377.08378369, 59504.93791765, 59633.1467344, 59763.72088164,
                59886.39027783, 60019.02739838, 60147.06211421, 60278.91505155,
                60400.41707501, 60526.78944757, 60651.09681352, 60773.59377531,
                60903.3130914, 61035.07430937, 61161.05200311, 61286.28399277,
                61419.73128784, 61548.88168331, 61678.23125819, 61817.95792148,
                61948.2306147, 62091.7046512, 62226.53485998, 62367.68337618,
                62504.82268713, 62644.56529322, 62791.4105829, 62937.55206985,
                63094.47498604, 63249.99101185, 63405.82395567, 63558.83126992,
                63730.35479375, 63893.18410211, 64063.05247982, 64234.61509263,
                64418.23843848, 64606.76243476, 64800.75451622, 65009.26210584,
                65219.78865272, 65435.37137585, 65684.50945914, 65933.51808688,
                66192.20550111, 66475.37401097, 66770.66277284, 67101.61275613,
                67448.96286764, 67844.22369744, 68294.14575387, 68836.7503846,
                69484.01436583, 70336.85011311, 71689.84667803, 82113.06510423);

        List<Double> dataPoit_list = new ArrayList();
        dataPoit_list.add(40425.00);
        dataPoit_list.add(53590.00);
        dataPoit_list.add(54622.00);
        dataPoit_list.add(56802.00);
        dataPoit_list.add(50664.00);
        dataPoit_list.add(58086.00);
        dataPoit_list.add(59624.00);
        dataPoit_list.add(52641.00);
        
        for (int i = 1; i <array.size(); i++) {
            for(Double x: dataPoit_list){
                if(array.get(i)>x&&array.get(i-1)<x){
                    array.add(array.indexOf(array.get(i)),x);
                 }
                else if(array.get(0)>x){
                    array.add(0,x);
                }
            }
        }
        for (int i = 0; i <array.size(); i++) {
            for (Double x:dataPoit_list) {
                if(array.get(i).equals(x)){
                    System.out.println("The placement of the values from the dataPoit_list (The value is the nth element of the first array): "+(array.indexOf(array.get(i))+1));
                }
            }
        }`
DanE
  • 30
  • 7
  • But when i added the last value which is 82113.06510423 of the array in it. why it is telling me that this will be at 102 position? – Irfan Yaqub Dec 23 '21 at 13:23
  • @MR.Robot Because if you insert values in a list it's size will be bigger than it was before, like, imagine if you would be at a running competition and suddenly a guy would jump in front of you, therefore the whole placement would change, so the last would be 101 not 101 :) Hope this helped to understand it. – DanE Dec 23 '21 at 13:53
  • Please correct me if I am wrong, I have selected an item from the 2nd index which is 50637.6692345 and another number selected between the number of the 8th and 9th index, which is 53595.00. This is still giving me both of them at 3rd place. Kindly explain this, please. – Irfan Yaqub Dec 23 '21 at 15:06