Fun with ChatGPT

I'll spare you the blow-by-blow.

I asked

I would like your help with a function, to be written in C++. I have a game with a "deck" of cards. The different cards are just numbers 0 to 51, so I have an array of length 52. I can load a deck, shuffle it and deal it just fine. I am stuck however with how to put the deck back in order after extended game play. So I need that in a function.


Okay, the more clever among you can just keep it to yourselves for now.

We went around and around, ChatGPT offered a number of sorting functions, sometimes identical to one it had previously, none of which worked.

Once we were going in circles I had to say

Not [helping] much. I just wanted to put the cards in the array in order, my teacher says this is a sorting problem and is like 1/3 of all that computers do - shouldn't we be able to sort an array?

It offered an insertion sort example in Python. I asked it to rewrite it in C++, and finally! I get my sorted deck.

Then I said (spoiler alert!)

OK! That works. It occurs to me, however, that since the shuffle just ends up with each array element being equal to the index, wouldn't it have been simpler to just load the deck array with the numbers 0..51?

and without a hint of shame or irony it replied

Yes, you're right. Since the shuffled deck is just a permutation of the integers from 0 to 51, you could have just initialized the deck array with those numbers instead of shuffling them. Here's how you could modify the code to do that:

and offered the code

void initializeDeck(int deck[]) {
    for (int i = 0; i < 52; i++) {
        deck[i] = i;
    }
}

void sortDeck(int deck[]) {
    for (int i = 1; i < 52; i++) {
        int j = i;
        while (j > 0 && deck[j - 1] > deck[j]) {
            int temp = deck[j];
            deck[j] = deck[j - 1];
            deck[j - 1] = temp;
            j--;
        }
    }
}

and the explanation

With this modification, you don't need to call the shuffleDeck function at all. The initializeDeck function will fill the array with the integers 0 to 51, and then sortDeck will sort them in ascending order.

I did not have it in my heart to continue. We parted on good terms.

a7

1 Like

It is fun to have chatGPT write oneself a short biographical essay, say 200 words. I just learned that I am a professor at Stanford University!

The chatGPT bios I've seen are uniformly glowing, and generally fact free, but who cares?

2 Likes

There is such a wide base of garbage code. GPT has it's pick of terrible solutions to damn near any problem.

I tend to stick with the ART version of AI right now.
Some of the best memes ever.
Most of which I could never post on here as they might be considered a violation in some form or another LOL

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.