News for hackers. Stuff that matters.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by TakeBlaster16 on Saturday August 20, 2022 @01:12PM (#32533598)
I had no idea GPT-3 could write code! It seems to do pretty well even with a one-sentence prompt:

  Write a C++ program that computes the dot product of two three-dimensional vectors.
---

  #include <iostream>
  #include <cmath>
  using namespace std;
  
  int main()
  {
      double x1, x2, x3, y1, y2, y3;
      
      //Get input for vector 1
      cout << "Enter x1: ";
      cin >> x1;
      cout << "Enter y1: ";
      cin >> y1;
      cout << "Enter z1: ";
      cin >> z1;
      
      //Get input for vector 2
      cout << "Enter x2: ";
      cin >> x2;
      cout << "Enter y2: ";
      cin >> y2;
      cout << "Enter z2: ";
      cin >> z2;
      
      //Calculate the dot product
      double dot_product = x1*x2 + y1*y2 + z1*z2;
      
      //Print the result
      cout << "The dot product is: " << dot_product << endl;
      
      return 0;
  }
EDIT: It even does Rust, I'm blown away! (I'll forgive the compile error, it's close enough)

  fn main() {
      let v1 = vec![1, 2, 3];
      let v2 = vec![4, 5, 6];

      let dot_product = v1.iter().zip(v2).map(|(x, y)| x * y).sum();

      println!("The dot product of {:?} and {:?} is {}", v1, v2, dot_product);
  }
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by goodside on Saturday August 20, 2022 @01:19PM (#32533650)
In general, anything that has a “textbook” solution is easy. What it’s doing here is more recitation than synthesis. Where it becomes harder, and where my method is necessary, is when you need to specify the structure of the solution yourself because the model can’t get there on its own.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by lossolo on Sunday August 21, 2022 @11:57AM (#32541405)
Exactly, that's why GPT3 generated things that were not included in task description in C++ example like reading the numbers first and then printing them. Same thing in Rust, here vectors are static, while in C++ you were asked. All because of examples on which the model was trained.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by b20000 on Saturday August 20, 2022 @06:38PM (#32535772)
the reason it does well is because you gave it a question that might come up in coding interviews.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by michannne on Saturday August 20, 2022 @06:51PM (#32535858)
I think that's amazing on its own. Rather than having to do a leetcode hard on the fly, you can just ask for the solution. You'll still need to know the problem space in order to properly optimize it, but it can save a lot of time.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by Max-q on Saturday August 20, 2022 @06:01PM (#32535536)
It’s incredible. I have used it to make several arduino programs for me, controlling different hardware and connecting them. It’s just amazing.