4 ms·
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 th
by TakeBlaster16 4y ago
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);
}
- goodside 4y agoIn 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.
- lossolo 4y agoExactly, 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.
- Max-q 4y agoIt’s incredible. I have used it to make several arduino programs for me, controlling different hardware and connecting them. It’s just amazing.
- b20000 4y agothe reason it does well is because you gave it a question that might come up in coding interviews.
- michannne 4y agoI 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.