how the fantasy app divide the prize money in winners, how the calculation do?

54 Views Asked by At

Currently i calculated the prize based on number of winners, but this method not work as like as fantasy app divide the prize money in winners. i try to found on internet, but i found nothing related to that, i found at math.stackexchange.com something like that i don't know how is that useful for me.

https://math.stackexchange.com/questions/714280/dividing-amount-unequally-in-tournament-winners

i am working the project in java.

i try these

public class AlgorithmForCustomContest {
private static final Map<Integer, List<Double>> WINNER_DISTRIBUTION = new HashMap<>();

    static {
        WINNER_DISTRIBUTION.put(1, Collections.singletonList(100.0));
        WINNER_DISTRIBUTION.put(2, Arrays.asList(70.0, 30.0));
        WINNER_DISTRIBUTION.put(3, Arrays.asList(50.0, 30.0, 20.0));
        WINNER_DISTRIBUTION.put(4, Arrays.asList(40.0, 25.0, 20.0, 15.0));
        WINNER_DISTRIBUTION.put(10, generate10WinnerDistribution());
        WINNER_DISTRIBUTION.put(50, generate50WinnerDistribution());
}

public static ArrayList<WinnersPrizesModel> calculatePrizes(int numWinners, int contestPrize) {
        List<Double> distribution = WINNER_DISTRIBUTION.get(numWinners);
        if (distribution == null) {
            throw new IllegalArgumentException("No distribution found for " + numWinners + " winners.");
        }

        ArrayList<WinnersPrizesModel> winnersList = new ArrayList<>();
        int start = -1;
        int end = -1;
        int lastPrize = -1;
        for (int i = 0; i < numWinners; i++) {
            double prize = (double) contestPrize * distribution.get(i) / 100.0;
            int prizeRound = (int) Math.round(prize);

            if (prizeRound != lastPrize) {
                if (start != -1 && end != -1 && start != end) {
                    String winner = "# " + start + "-" + end;
                    String winPrize = "₹"+formatPriceWithCommas(lastPrize);
                    winnersList.add(new WinnersPrizesModel(winner, winPrize));
                } else if (start != -1) {
                    String winner = "# " + start;
                    String winPrize = "₹"+formatPriceWithCommas(lastPrize);
                    winnersList.add(new WinnersPrizesModel(winner, winPrize));
                }
                start = i + 1;
            }
            end = i + 1;
            lastPrize = prizeRound;
        }

        if (start != -1 && end != -1 && start != end) {
            String winner = "# " + start + "-" + end;
            String winPrize = "₹"+formatPriceWithCommas(lastPrize);
            winnersList.add(new WinnersPrizesModel(winner, winPrize));
        } else if (start != -1) {
            String winner = "# " + start;
            String winPrize = "₹"+formatPriceWithCommas(lastPrize);
            winnersList.add(new WinnersPrizesModel(winner, winPrize));
        }

        return winnersList;
    }


 private static List<Double> generate10WinnerDistribution() {
        List<Double> distribution = new ArrayList<>();
        distribution.add(30.0);
        distribution.add(18.0);
        distribution.add(11.0);
        distribution.add(7.5);
        distribution.add(6.0);
        addMultiple(distribution, 5, 5.5);
        return distribution;
    }

private static List<Double> generate50WinnerDistribution() {
        List<Double> distribution = new ArrayList<>();
        distribution.add(15.0);
        distribution.add(10.0);
        distribution.add(8.0);
        distribution.add(4.0);
        distribution.add(3.0);
        addMultiple(distribution, 5, 2.0);
        addMultiple(distribution, 15, 1.5);
        addMultiple(distribution, 25, 1.1);
        return distribution;
    }

private static void addMultiple(List<Double> list, int count, double value) {
        for (int i = 0; i < count; i++) {
            list.add(value);
        }
    }
}

and i expect the prize distribution in all winners like dream 11, take an example of 1.6cr total prize pool. see in this picture here

0

There are 0 best solutions below