/*
Online Java - IDE, Code Editor, Compiler
Online Java is a quick and easy tool that helps you to build, compile, test your programs
online.
*/
import java.util.*;
import java.math.*;
import java.lang.reflect.Array;

interface Rollable
{
    public int roll();
}

public class Main
{
    public static void main(String[] args) 
    {
        int numberDice=6;
        
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        diceRoll d = new diceRoll(numberDice,33);
    }
}

class diceRoll implements Rollable
{
    Set <String> s = new HashSet<>();
    private int total;
    private int totalRolled;
    int numberDice;
    
    public int roll()
    {
        
        int[] diceValue = new int[numberDice];
        int count;
        Random rnd = new Random();
        
        int numberDiceRolls=750000;

        System.out.println("\nNumber dice rolls: " + numberDiceRolls + " for " + numberDice + " dice");
        System.out.println("Total: " + total);
        
        for (int i=0;i<numberDiceRolls;i++)
        {
            StringJoiner sj = new StringJoiner(", ");
            totalRolled=0;
            
            for (int j=0;j<numberDice;j++)
            {
                diceValue[j]=(rnd.nextInt(numberDice)+1);
                totalRolled=totalRolled+diceValue[j];

                sj.add("Die " + (j+1)+": " + Integer.toString(diceValue[j]));
            }
            
            if (totalRolled==total)
            {
                s.add(sj.toString());
            }
        }
        count=0;
        
        for (String m: s)
        {
            System.out.println("\n"+ m);
            count++;
        }
        
        System.out.println("\nTotal number possibilites: " + count);
            
        return count;
    }
        
    public diceRoll(int numberDice, int total)
    {
        this.numberDice=numberDice;
        this.total=total;
            
        if (total<numberDice)
        {
            System.out.println("Increase total or reduce number dice");
            System.exit(0);
        }
            
        if (total>(6*numberDice))
        {
            System.out.println("The total is too high for: " + numberDice + " dice");
            System.exit(0);
        }
        roll();
    }
}