Comment

Comment by tachim

Easy fix. Prompt:

  Write an efficient, not brute force, program that solves the following problem: suppose we have two unknown quantities x and y. If three time x plus two times y is twenty, and 2 times x plus three time y is ten, what are x and y?
Output:

  One way to solve this problem efficiently is to use the method of elimination. We can set up a system of equations as follows:

  3x + 2y = 20
  2x + 3y = 10

  We can then multiply the first equation by 2 and the second equation by 3, to get:

  6x + 4y = 40
  6x + 9y = 30

  We can then subtract the second equation from the first equation, to get:

  -5y = 10
  y = -2

  We can then substitute this value of y into one of the original equations (for example, the first one), to get:

  3x + 2(-2) = 20
  3x - 4 = 20
  3x = 24
  x = 8

  Therefore, the values of x and y are x = 8 and y = -2.
parent tachim 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton