Comment

Comment by TakeBlaster16

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);
  }

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton