2

I'm trying to implement Korf's algorithm to generate all Rubik's cube corners permutations. In total it must be 8! * 3^7(88,179,840), but the program gets Killed after generating around (36,000,000) permutations. I used Lehmer code indexing for the permutations and created a table of size (88,179,840) knowing that the index would never surpass that value. uint32_t *table = (uint32_t *)calloc(88179840, sizeof(uint32_t));. I checked the result of the indexing function and it gives the right result... for example the permutation (0, 1, 2, 3, 4, 5, 6, 7) it gives 0 and in (7, 6, 5, 4, 3, 2, 1, 0) it gives 40319. I made a BFS function to expand nodes and get all the permutations and index them. then store them in a file.

    void bfs(t_state *top, t_state *tail)
{
    uint32_t i, childCost;
    uint32_t permIndex;
    t_state *curr;
    t_cube new_cube;
    uint32_t *onesCount;
    uint32_t *table = (uint32_t *)calloc(88179840, sizeof(uint32_t));
    FILE *fp;

    fp = fopen("./perms.txt", "w+");
    onesCount = table_of_ones();
    permIndex = get_corner_index(top->cube, onesCount, fp);
    fprintf(fp, "%d|%d \n", permIndex, 0);
    table[permIndex] = 1;
    while (top)
    {
        curr = pop(&top);
        childCost = curr->cost + 1;
        i = 1;
        while (i < 19)
        {
            new_cube = apply_move(curr->cube, i, "");
            permIndex = get_corner_index(new_cube, onesCount, fp);
            if (table[permIndex] == 0)
            {
                table[permIndex] = 1;
                fprintf(fp, "%d|%d\n", permIndex, childCost);
                tail = push(tail, new_cube, childCost);
                if (top == NULL)
                    top = tail;
            }
            i++;
        }
        free(curr);
    }
    fclose(fp);
    free(onesCount);
}

i used htop to keep track of memory, and this is a screenshot of the memory sec bfr it got killed

photo of the program when it gets killed enter image description here

0 Answers0