comp.lang.ada
 help / color / mirror / Atom feed
From: Anatoly Chernyshev <achernyshev@gmail.com>
Subject: ChatGPT
Date: Thu, 30 Mar 2023 14:49:43 -0700 (PDT)	[thread overview]
Message-ID: <3db3c046-bbcf-497b-afd5-ac6c2b9567afn@googlegroups.com> (raw)

Just had an exercise with ChatGPT for Ada.

Here is what my request was: "Produce Ada code for solving a quadratic equation."

And here's the output from ChatGPT (quite flawless forgiving the absence of a math lib in the header):
----------------------------
with Ada.Text_IO; use Ada.Text_IO;

procedure Quadratic_Equation is
   A, B, C, D : Float;
   X1, X2 : Float;
begin
   -- read coefficients A, B, and C from the user
   Put("Enter coefficient A: ");
   Get(A);
   
   Put("Enter coefficient B: ");
   Get(B);
   
   Put("Enter coefficient C: ");
   Get(C);

   -- calculate the discriminant
   D := B*B - 4.0*A*C;

   -- check if the discriminant is negative
   if D < 0.0 then
      Put_Line("No real roots exist.");
   else
      -- calculate the roots
      X1 := (-B + Sqrt(D)) / (2.0*A);
      X2 := (-B - Sqrt(D)) / (2.0*A);
      
      -- output the roots
      Put_Line("Root 1 = " & Float'Image(X1));
      Put_Line("Root 2 = " & Float'Image(X2));
   end if;
end Quadratic_Equation;

and an extra remark:

Note that this implementation assumes that the discriminant (B^2 - 4AC) is positive or zero. If the discriminant is negative, then no real roots exist.
-----------------------------------------------

Before crying wolf, my impression is that ChatGPT might be useful for drafting simple pieces of code (say, homeworks). Very soon though one will arrive at a situation when the amount of efforts to explain the task to ChatGPT will be the same as to write the code yourself (I shall call it a limiting Kolmogorov complexity).

What do you think?



             reply	other threads:[~2023-03-30 21:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30 21:49 Anatoly Chernyshev [this message]
2023-03-30 22:32 ` ChatGPT Jerry
2023-04-01 12:10   ` ChatGPT Hou Van Boere
2023-03-30 23:00 ` ChatGPT Jeffrey R.Carter
2023-03-31  6:54   ` ChatGPT Dmitry A. Kazakov
2023-03-31 11:04     ` ChatGPT magardner2010
2023-03-31 21:44     ` ChatGPT Anatoly Chernyshev
2023-04-01  7:39       ` ChatGPT Dmitry A. Kazakov
2023-04-07  1:51         ` ChatGPT Ken Burtch
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox