Skip to content

Instantly share code, notes, and snippets.

@jkaunert
Last active February 12, 2020 16:26
Show Gist options
  • Save jkaunert/eb9998ef2ca666db35e457261b897b4f to your computer and use it in GitHub Desktop.
Save jkaunert/eb9998ef2ca666db35e457261b897b4f to your computer and use it in GitHub Desktop.
iOSCodeChallenge-Sprint02-02.md

CHALLENGE

  • 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.

@solaikulola
Copy link

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 3
3 ==9
enum sumAnd product(5,6)
var 3+2 =5
var 3*2 = 6
return [3,2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment