News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

ChatGPT+Gemini Experiments

Started by zedd151, December 30, 2024, 03:40:41 PM

Previous topic - Next topic

zedd151

While chatgpt does not yet write very good masm32 assembly (usually needs too many corrections), it does fairly well writing C code.
I have been having chatgpt write some sudoku related functions, and most of the time the code compiles just fine and actually works. It has a better chance of doing sudoku right, than many C sudoku related examples on github that I have been investigating.

To finish my sudoku project I will either have to convert all of my asm code to C (very highly unlikely), convert the C code assembly listing to masm compatible assembly (can be tricky), or maybe even link the C functions to my assembly code. Hmmm...

So far though, I have had zero success linking the *.o files with any *.obj files. I have no clue what format the *.o files are. I can only assume some compatibility issue.

I am using dev C++ for the C code, which uses gcc as compiler.

Will post some of the code soon... I hope. (In a more appropriate section)

:cool:

zedd151

Well, rats!

QuoteYou've hit the Free plan limit for GPT-4o.
Responses will use another model until your limit resets tomorrow after 2:22 AM.

And things were going so well.  :tongue:

For anyone interested, I am working on code to count all possible solutions in a sudoku grid. To both ensure the grid is valid and is unique (it must have exactly 1 solution). I have asm code to very quickly generate a filled sudoku puzzle (can fill 1000 grids in 500-600 ms. without repeated grids), I also have code to remove values from the grid. ANd two different fast solvers (needed for puzzle generation) This piece is final step needed to make a very fast sudoku puzzle generator which only generates valid puzzles with a unique solution.  :azn:
:cool:

jimg

 I have been using chatgpt for a few weeks now, and I've found it a great time saver when researching something I'm not familiar with.  One thing I like is never worrying about asking a really dump question.

It still has a penchant for trying to do memory to memory moves when filling out a structure, but those are easy to fix.  If it creates code with too many syntax errors, just feed the errors back in, and it will fix most of them.

I've also run into the time limit several times, but the "other model" just keeps on working, if a bit more slowly.

How does it work if you feed it the C code and ask it to convert it to masm?  Any better than using the compiler output?

TimoVJL

Quote from: zedd151 on December 30, 2024, 03:40:41 PMSo far though, I have had zero success linking the *.o files with any *.obj files. I have no clue what format the *.o files are. I can only assume some compatibility issue.

I am using dev C++ for the C code, which uses gcc as compiler.

try this for that *.o object files
objconv
Many C/C++ compilers use symbols from compiler support libraries, so many object files wont work alone.
May the source be with you

zedd151

Thanks Timo. I have heard of objconv before, but had never needed to use it, so forgot it exist. I will try that later today. That will make the job easier, if it works.  :azn:  I see that is Agners work, should be good.
:cool:

daydreamer

#5
Zedd ,Here I use vc++ helping me port old Java code to masm
https://masm32.com/board/index.php?topic=7708.0
Also check that subforum for more info on port c to masm

Zedd isn't it time to code a zedd ai script,that emulates zedd long after your gone ? :)

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

zedd151

#6
Quote from: daydreamer on December 31, 2024, 07:02:22 AMZedd isn't it time to code a zedd ai script,that emulates zedd long after your gone ? :)
Gone??? That is alarming, where did that come from? I ain't going anywhere anytime soon.  :tongue:

A sneak peek at the latest chatgpt "C" code. Works flawlessly, but needs to be expanded quite a lot to add more solving methods and techniques...  :biggrin:

#include <stdio.h>
#include <stdbool.h>

#define SIZE 9

// Function to count pre-filled cells in the Sudoku puzzle
int count_prefilled_cells(int grid[SIZE][SIZE]) {
    int count = 0;
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            if (grid[i][j] != 0) {
                count++;
            }
        }
    }
    return count;
}

// Function to evaluate the distribution of pre-filled cells
int evaluate_distribution(int grid[SIZE][SIZE]) {
    int row_filled[SIZE] = {0};
    int col_filled[SIZE] = {0};

    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            if (grid[i][j] != 0) {
                row_filled[i]++;
                col_filled[j]++;
            }
        }
    }

    int row_score = 0, col_score = 0;
    for (int i = 0; i < SIZE; i++) {
        row_score += (row_filled[i] > 0);
        col_score += (col_filled[i] > 0);
    }

    return row_score + col_score;
}

// Function to check if two cells form a Naked Pair
bool is_naked_pair(int candidates1[SIZE], int candidates2[SIZE]) {
    int count1 = 0, count2 = 0;
    for (int i = 1; i <= SIZE; i++) {
        if (candidates1[i]) count1++;
        if (candidates2[i]) count2++;
    }
    if (count1 == 2 && count2 == 2) {
        for (int i = 1; i <= SIZE; i++) {
            if (candidates1[i] != candidates2[i]) {
                return false;
            }
        }
        return true;
    }
    return false;
}

// Function to check for X-Wing patterns
bool check_x_wing(int grid[SIZE][SIZE], int candidate) {
    int rows[SIZE][SIZE] = {0};
    int cols[SIZE][SIZE] = {0};

    // Track candidate positions in rows and columns
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            if (grid[i][j] == 0) {
                rows[i][j] = 1;
                cols[j][i] = 1;
            }
        }
    }

    // Check rows and columns for X-Wing patterns
    for (int r1 = 0; r1 < SIZE - 1; r1++) {
        for (int r2 = r1 + 1; r2 < SIZE; r2++) {
            int count = 0, cols_found[2];
            for (int c = 0; c < SIZE; c++) {
                if (rows[r1][c] && rows[r2][c]) {
                    cols_found[count++] = c;
                    if (count > 2) break;
                }
            }
            if (count == 2) {
                // Found an X-Wing
                return true;
            }
        }
    }
    return false;
}

// Function to check solving methods needed
void check_solving_methods(int grid[SIZE][SIZE]) {
    int has_hidden_singles = 0;
    int has_naked_pairs = 0;
    int has_x_wing = 0;

    // Example candidate matrix (1 to SIZE for each cell)
    int candidates[SIZE][SIZE][SIZE + 1] = {0};

    // Populate candidates (placeholder logic)
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            if (grid[i][j] == 0) {
                for (int k = 1; k <= SIZE; k++) {
                    candidates[i][j][k] = 1;
                }
            }
        }
    }

    // Check for Naked Pairs
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE - 1; j++) {
            for (int k = j + 1; k < SIZE; k++) {
                if (is_naked_pair(candidates[i][j], candidates[i][k])) {
                    has_naked_pairs = 1;
                }
            }
        }
    }

    // Check for X-Wing
    for (int num = 1; num <= SIZE; num++) {
        if (check_x_wing(grid, num)) {
            has_x_wing = 1;
        }
    }

    printf("\nSolving Methods Required:\n");
    if (has_hidden_singles) {
        printf("- Hidden Singles\n");
    }
    if (has_naked_pairs) {
        printf("- Naked Pairs\n");
    }
    if (has_x_wing) {
        printf("- X-Wing\n");
    }
    if (!has_hidden_singles && !has_naked_pairs && !has_x_wing) {
        printf("- Basic Elimination\n");
    }
}

// Function to rate the difficulty of the Sudoku puzzle
const char* rate_sudoku(int grid[SIZE][SIZE]) {
    int prefilled = count_prefilled_cells(grid);
    int distribution = evaluate_distribution(grid);

    if (prefilled >= 36 && distribution >= 14) {
        return "Easy";
    } else if (prefilled >= 28 && distribution >= 12) {
        return "Medium";
    } else {
        return "Hard";
    }
}

// Function to display the Sudoku puzzle
void display_grid(int grid[SIZE][SIZE]) {
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            printf("%d ", grid[i][j]);
        }
        printf("\n");
    }
}

int main() {
    // Example Sudoku puzzle (0 represents empty cells)
    int sudoku[SIZE][SIZE] = {
{0, 8, 0, 0, 3, 0, 0, 9, 0},
{0, 0, 0, 0, 0, 4, 5, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 8, 0},
{1, 0, 0, 0, 0, 0, 7, 0, 0},
{0, 0, 7, 5, 0, 6, 4, 0, 0},
{0, 6, 9, 0, 0, 0, 0, 0, 8},
{0, 2, 0, 0, 0, 0, 0, 7, 6},
{0, 0, 6, 2, 0, 0, 0, 0, 0},
{7, 9, 0, 0, 1, 0, 0, 3, 0}
  };

    printf("Given Sudoku Puzzle:\n");
    display_grid(sudoku);

    const char* difficulty = rate_sudoku(sudoku);
    printf("\nDifficulty Rating: %s\n", difficulty);

    check_solving_methods(sudoku);

    return 0;
}

Quote from: daydreamer on December 31, 2024, 07:02:22 AMZedd ,Here I use vc++
I have thought about 'biting the bullet' and using VS... but only briefly. DevC++ seems a lot simpler to use/set up. But I might eventually go that route, especially when I get into more complex code. (Meaning the bits and pieces that are not easily converted to asm)
:cool:

TimoVJL

Here that C example's obj-files compiled with msvc 2022
May the source be with you

zedd151

Quote from: TimoVJL on December 31, 2024, 08:29:05 AMHere that C example's obj-files compiled with msvc 2022
Thanks, Timo.
:cool:

daydreamer

Doesnt modern compilers use big booleans for speed,at least byte size and avoid old bit manipulation used when memory was small ?
I got an idea of save sieve data in 1 bit .bmp format ,at the same time curious how primes looks like for example in 256*256 grid or bigger square
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

zedd151

What exactly do you mean by 'big boolean', daydreamer?
Boolean means 1 or 0, true or false, yes or no, etc. One bit is big enough for that.

As far as using bits to store the prime number array, I think the bit manipulation code would make an algorithm slower than simply using a byte array. I could be wrong though.

Speaking of prime numbers, I came across some code that uses square roots and floating point to determine the primacy of a given integer. It works well, but slower than my Prime Sieve. I just don't know why or how it works. (The code that uses sqrt and floats, to determine primacy). Anyway, I know that is just as accurate as the sieve method, I tested primes up to 1000000000 and output a list for both functions. It was 100% match, as it should be. But as said it is slower as it does not use an array as the sieve does, but has to factor for primes at each iteration from 0-1000000000, which takes time.   :smiley:  But for a one-off check of a given very large integer, it is fast enough.
:cool:

daydreamer

zedd the idea is any image file ,read smaller file that is extracted to bytes or other bigger type in memory

i also been in c forum learning about square root trick is to limit division test loop to stop when it exceeds the square root of input number
Division is slow
Fsqrt is slow
Sieve has heavy use on caches


my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

zedd151

My ChatGPT+sudoku adventures are going very well. I am slowly (not too slow, though) building up a collection of C functions for solving sudoku without using backtracking, or brute force methods. The algorithms themselves are fairly trivial to convert to masm compatible assembly, disregarding all C related startup code and all other non sudoku related code that is.
There are two dozen or so functions that I will be converting one at a time, and testing them, before putting the combined set of functions into a single asm project.  :azn:

I will finish well before the years end.   :biggrin:

There is a question though about attribution. Do I have to give credit to ChatGPT when publishing the converted code? Does anyone know?
:cool:

sinsi

Quote from: zedd151 on January 01, 2025, 03:30:19 PMDo I have to give credit to ChatGPT when publishing the converted code?
ChatGPT certainly doesn't give credit, so fuck em :biggrin:

MS were being sued because their AI was mining github? without attribution.

zedd151

Quote from: sinsi on January 01, 2025, 03:54:21 PM
Quote from: zedd151 on January 01, 2025, 03:30:19 PMDo I have to give credit to ChatGPT when publishing the converted code?
ChatGPT certainly doesn't give credit, so fuck em :biggrin:

MS were being sued because their AI was mining github? without attribution.
Kind of what I thought.  :thumbsup:
:cool: