ChatGPT: Write a program in BBC BASIC which draws a circle

Started by BasicBoy, January 04, 2023, 08:02:02

Previous topic - Next topic

BasicBoy

Just signed up to OpenAI, and my first ever interaction with this amazing (and slightly disconcerting) AI engine was as per the subject of this thread:

"Write a program in BBC BASIC which draws a circle"

Here's what it produced (unmodified by me):

   10 REM Program to draw a circle in BBC BASIC
   20 REM Set the radius of the circle
   30 radius = 50
   40 REM Set the center of the circle
   50 center_x = 100
   60 center_y = 100
   70 REM Set the starting angle
   80 angle = 0
   90 REM Set the step size for the angle
  100 step = 0.1
  110 REM Set the color of the circle
  120 color = 6
  130 REM Draw the circle
  140 FOR angle = 0 TO 6.283 STEP step
  150   x = center_x + radius*SIN(angle)
  160   y = center_y + radius*COS(angle)
  170   PLOT x, y, color
  180 NEXT angle
  190 END


The program actually runs without any errors reported, and a circle is displayed - kind of, but sadly ChatGPT doesn't yet understand how BBC BASIC's highly versatile PLOT command works. When used for plotting single pixels (or small rectangles in the case of rectangular 'pixels'), PLOT doesn't take a 3rd colour parameter in the way the AI thinks it does. Setting the graphics colour is usually done with a separate GCOL statement.

So, simply dropping the erroneous colour parameter, the program produces the expected output.

I've attached two cropped images from the program (one from the unmodified version, the other from the modified).

There will come a point in the not too distant future when ChatGPT will be able to create our SyntaxBomb game contest entries!  :o


Derron

You know you can simply paste errors you received from the compiler into the chatgpt-prompt?
It will recreate the code and tries to avoid the error.

Also you can tell it stuff you just wrote to us: "PLOT doesn't take a 3rd colour parameter in the way the AI thinks it does. Setting the graphics colour is usually done with a separate GCOL statement."
I bet it will say "oh you are correct, I made a mistake ..." and then does it differently (or not ...depending on how much it knew about your coding language of choice.



bye
Ron

BasicBoy

Quote from: Derron on January 04, 2023, 08:17:18
You know you can simply paste errors you received from the compiler into the chatgpt-prompt?
It will recreate the code and tries to avoid the error.

Yeah, I quickly discovered that. Amazing stuff.

On a second regeneration of the program I had to teach the AI that INK is not a valid keyword in BBC BASIC. It agreed with me: "You are correct, the INK command is not a part of BBC BASIC. In BBC BASIC, you can use the PAPER and INK statements to set the background and foreground colors of the screen, respectively."

Which is wrong!

Neither INK nor PAPER are valid keywords in BBC BASIC, so after informing the bot of this, it said: "I apologize for the mistake. In BBC BASIC, the GCOL (Graphics COLor) statement is used to set the color of graphics output, such as lines and circles."

It then produced a mostly correct 3rd program.

Notably, the first program it generated (which I coped & pasted into my initial post) didn't include INK, PAPER or GCOL.

BasicBoy

So I tried this for fun...

ChatGTP: Write a program in BBC BASIC which displays all the prime numbers between 1 and 100

This is what the bot generated:

10 REM Prime number program
20 FOR num = 2 TO 100
30   prime = 1
40   FOR div = 2 TO INT(SQR(num))
50     IF num MOD div = 0 THEN prime = 0: EXIT FOR
60   NEXT
70   IF prime THEN PRINT num;
80 NEXT
90 END


It works just fine!

I like how it knows about 'EXIT FOR' as well.

The future really is here...


BasicBoy

I wonder if anyone else can persuade ChatGTP to generate a program that gives accurate results for this task:

"Write a program in C which calculates the day of the week that Christmas Day falls on for any given year (the minimum year is 1900)."

It produces valid code, but its calculations are wrong, therefore giving the wrong results. I've had the bot generate programs for this task in BBC BASIC, C and Python -- all valid code generated, but it seems to be a really hard problem for it to get the calculations right.

I tell the bot that its program says that Christmas Day 2020 falls on a Saturday, when in fact it falls on a Friday. It acknowledges that it produces incorrect results, gives reaons why, and then spits out a revised version... which still produces incorrect results.

I'm not expecting miracles, but I'm a bit surprised it can't get this right after multiple attempts.