• [deleted]
    + 2 comments

    I had the same question and still don't get the answer.

    My solution was (dynamic programming approach):

    private static String winner(int n) {
        String[] memory = new String[101];
        Arrays.fill(memory, "");
        return winner(n, memory);
    }
    
    private static String winner(int n, String[] memory){
    
        if(n == 1){
            return "Second";
        }
    
        if(2 <= n  && n <= 5){
            return "First";
        }
    
        if(memory[n] == ""){
            if(winner(n - 5, memory) == "First"
                    && winner(n - 3, memory) == "First"
                    && winner(n - 2, memory) == "First"){
                memory[n] = "Second";
            }
            else{
                memory[n] = "First";
            }
        }
    
        return memory[n];
    
    }
    

    which is longer than this solution and recursive but makes sense to myself. I'd like to understand the reasoning of the other solution, more specifically this sentence:

    mod 7 is taken because max is 5 and min is 2, so at the climax of game atmost 7 cards are left.