- Write a function
sumAndProduct(_:)
that takes two positive integers, a sum and a product, and returns the smallest two positive integers x and y, where x + y == sum, and x * y == product. - Return x and y in an array with the smaller number first in the format [x, y]
- If a solution cannot be found, return the empty array
// Example: sumAndProduct(6, 9) should return [3, 3] because 3 + 3 == 6, and 3 * 3 == 9.
Here are the overall instructions for code challenges, if you need a reminder. Please create your own gist, don't comment on this one or you might inadvertently spoil the answer for other people. When you're done, submit your gist using this form.
enum (x y) = xy
var x sum y = (x+y)
var x product y = (xy)
//Example: sumAnd products(6,9) should return (3,3) when 3+3==6 ,and 33 ==9
enum sumAnd product(5,6)
var 3+2 =5
var 3*2 = 6
return [3,2]