//based on this cahllenge and guideline 2:
/*
2. if a player goes over 21, they lose immediately.. Since we are returning a String, only way is to append
two Strings in order to demonstrate both players have lost....
*/


public class Solution 
{
    public static void main (String[] args)
    {
        /*
        //Test Case 1 
        int [] player1 = new int[]{10, 9};
        int [] player2 = new int[]{8, 7};
        */
        
        /*
        //Test Case 2 
        int [] player1 = new int[]{10, 12};
        int [] player2 = new int[]{8, 7};
        */
        
         /*
        //Test Case 3 
        int [] player1 = new int[]{10, 9};
        int [] player2 = new int[]{10, 9};
        */
         
        //Test Case 4 
        int [] player1 = new int[]{10, 9};
        int [] player2 = new int[]{8, 7};
        
        blackjack(player1, player2);
    }
    
    public static String blackjack(int[] player1, int[] player2) 
    {
        int totalPlayer1=0;
        int totalPlayer2=0;
        String outcome="";

        for (int x: player1)
        {
            totalPlayer1 = totalPlayer1 + x;
        }

        for (int y:player2)
        {
            totalPlayer2 = totalPlayer2 + y;
        }

        //best to categorize into sections to avoid ambiguity
        //first deal with if either over 21.
        //note this also covers both over 21

        if (totalPlayer1>21 || totalPlayer2>21)
        {
            if (totalPlayer1>21)
            {
                System.out.println("Player 1 lose");

                outcome = "Player 2 wins";
            }

            if (totalPlayer2>21)
            {
            System.out.println("Player 2 lose");

            outcome = outcome + " Player 1 wins";
            }
        }

        //the logic here would be that neither are over 21... so both are valid...
        //do we really need to check for blackjack, not really.
        //since we are comparing against 21
        else
        {
            if ((21-totalPlayer1)==(21-totalPlayer2))
            {
                System.out.println("Draw");
                outcome="Draw";
            }

            //now we need to examine who has the smallest gap from 21.. They would be declared the winner
            else
            {
                if ((21-totalPlayer1)<((21-totalPlayer2)))
                {
                    System.out.println("Player 1 wins");
                    outcome = "Player 1 wins";
                }
                else
                {
                    System.out.println("Player 2 wins");
                    outcome = "Player 2 wins";
                }
            }
        }

        return outcome;
    }
}