private static void recurse(Set<Way>[][] ants, boolean[][] hasMoved, int count) {
        if (count == n*n) {
            f++;
            if (n == 4 || f % 10000 == 0) {
                System.out.println(f);
                printAnts(ants);
            }
            return;
        }
        int leastX = -1;
        int leastY = -1;
        int moves = Integer.MAX_VALUE;

        for (int x = 0; x < n; x++) {
            for (int y = 0; y < n; y++) {
                if (!hasMoved[x][y] && ants[x][y].size() < moves) {
                    moves = ants[x][y].size();
                    leastX = x;
                    leastY = y;
                }
            }
        }

        for(Way way : ants[leastX][leastY]) {
            move(leastX, leastY, way, deepCopy(ants), deepCopy(hasMoved), count);
        }
    }