import java.util.*;
public class Main {
public static void main(String[] args) {
Long lowLimit = 200L;
Long highLimit = 210L;
// Create a list to store the result i.e total number of ways to choose sum so that max possible participants win the lottery, number of participants who will win the lottery
List<Long> finalResult = new ArrayList<>();
// Create a list to store Sum of digits of each number
List<Long> listDigit = new ArrayList<>();
// Loop through the lowLimit and highLimit to get the List of Sum of digits of each number
for (Long i = lowLimit; i <= highLimit; i++) {
Long j = i;
Long sum = 0L;
while (j != 0) {
sum = sum + j % 10;
j /= 10L;
}
listDigit.add(sum);
}
System.out.println("Sum " + listDigit);
// Create a HashMap to store the number of times each sum appears in the listDigit array.
// The key would be each unique number in listDigit and the value would be the number of times it appears in the listDigit array
Map<Long,Long> map = new HashMap<>();
for(Long i: listDigit) {
if(map.containsKey(i)) {
map.put(i, map.get(i) + 1L);
}else {
map.put(i, 1L);
}
}
System.out.println("Map: " + map);
// The max number of winners will be the maximum value in the map
Long winners = Collections.max(map.values());
System.out.println("Number of winners: " + winners);
// To get the number of ways to win, count the number of keys that have the maximum values in the map
Long ways = 0L;
for (Long sum : map.values()) {
if(Objects.equals(sum, winners)){
ways++;
}
}
System.out.println("Number of ways to win: " + ways);
finalResult.add(ways);
finalResult.add(winners);
System.out.println("Final result " + finalResult);
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: