## Bronze Challenge:

Easy enough. Implement the functionality of the `+`

operator to `Point`

:

```
struct Point: Comparable {
...
static func +(lhs: Point, rhs: Point) -> Point {
return Point(x: lhs.x + rhs.x, y: lhs.y + rhs.y)
}
}
```

**Gold Challenge:** I wasn’t able to get this one to stick in my head. Any help is appreciated!

## Platinum Challenge

First, I wanted to create a function to calculate the Euclidean Distance for a point (passing in the point you want to calculate the distance from, in case you want to pick something different than the origin (print statement for debugging purposes). Ths also included defining a new operator that could handle exponents in the function (found the solution for the `^^`

operator online, also sets precedence so things are calculated correctly):

```
/*
* creating the ^^ operator to use later in Euclidean Distance func.
* Also needs to be outside the struct, as it must be a file-level operator.
*/
precedencegroup ExponentiativePrecedence {
associativity: right
higherThan: MultiplicationPrecedence
}
infix operator ^^: ExponentiativePrecedence
public func ^^ (radix: Double, power: Double) -> Double {
return pow((radix), (power))
}
struct Point: Comparable {
...
func euclideanDistance(to other: Point) -> Double {
let distance = sqrt((Double(self.x) - Double(other.x))^^2 + (Double(self.y) - Double(other.y))^^2)
print("Calculated distance for (\(self.x), \(self.y)) to origin: \(distance)")
return distance
}
}
```

Then, you can use that in the `<`

operator definition to calculate the distance for each point passed in, and determine whether or not one is equal to the other:

```
struct Point: Comparable {
...
static func <(lhs: Point, rhs: Point) -> Bool {
let originPoint = Point(x: 0, y: 0)
let lhsDistance = originPoint.euclideanDistance(to: lhs)
let rhsDistance = originPoint.euclideanDistance(to: rhs)
return lhsDistance < rhsDistance
}
...
}
```

Now it works as expected.

Note for authors:learning about precedence at the end of the chapter would’ve been very helpful in one of the previous challenges when we were working on the lexer/parsing engine and had to figure out how to set precedence for multiplcation over addition and such (although I understand why it was mentioned in this chapter since this was focused on custom operators). Just pointing that out!