Chessboard Game, Again!

Sort by

recency

|

19 Discussions

|

  • + 0 comments

    +++

  • + 7 comments

    I'm not really sure if there's something wrong with my code or the way I considered playing the game is different than what's expected. My thought process is that, we are able to use any of the 4 possible moves, and at each move we want to make the most optimal move, rather than just get to the edge and try out best not to cross it. My logic is that we would always try to get to the centre of the board by reducing/increasing x or y while compromising the other one by the least amount possible. Somehow my results just don't match with the expected one. And it's such a long script I don't even know where things might be going wrong.

  • + 0 comments

    Can anyone help me below mentioned code showing wrong result for last 3 test case.

    import java.io.; import java.math.; import java.security.; import java.text.; import java.util.; import java.util.concurrent.; import java.util.function.; import java.util.regex.; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList;

    // class Result {

    public static HashMap<HashMap<Integer,Integer>,Integer> hm = new HashMap<>();
    public static int grundy(int x,int y){
        HashMap<Integer,Integer> p = new HashMap<>();
        p.put(x,y);
        if(hm.containsKey(p)) return hm.get(p); 
        HashSet<Integer> set = new HashSet<>();
        if(x>=1 && y>=1 && x<=15 && y<=15){
            set.add(grundy(x-2, y+1));
            set.add(grundy(x-2, y-1));
            set.add(grundy(x+1, y-2));
            set.add(grundy(x-1, y-2));
        }
        int mex;
        for(int i = 0; ; i++)
        {
            if(set.contains(i)){
                continue;
            }
            mex = i;
            break;
        }
        // g = !g;
        hm.put(p, mex);
        return mex;
    
     }
    
    public static String chessboardGame(int[][] coins) {
    // Write your code here
        int xorsum = 0;
        for(int i = 0; i < coins.length; i++){
            int x = coins[i][0];
            int y = coins[i][1];
    
            // System.out.println("x="+x+"  y ="+y);
    
            int g = grundy(x, y);
    
            xorsum ^= g;
            // System.out.println(g);
        }
        // System.out.println(hm);
        return xorsum == 0?"Second":"First";
    
    }
    

    }

    public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int k = sc.nextInt(); int[][] arr = new int[k][2]; for(int i = 0 ; i < k; i++){ arr[i][0] = sc.nextInt(); arr[i][1] = sc.nextInt(); } String result = Result.chessboardGame(arr); System.out.println(result); } } }

  • + 0 comments

    Here is Chessboard game again! problem solution in Python Java C++ and c programming - https://programs.programmingoneonone.com/2021/07/hackerrank-chessboard-game-again-problem-solution.html

  • + 0 comments

    Too difficult for me