Created
October 17, 2018 19:58
-
-
Save vialyx/e2bf6278cdaaf01da40c62a2807b85c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
infix operator +++: AdditionPrecedence | |
extension Engine { | |
static func +++ (left: Engine, right: Engine) -> Engine { | |
let tank = max(left.tank, right.tank) | |
let consumption = min(left.consumption, right.consumption) | |
return Engine(tank: tank, | |
consumption: consumption, | |
distance: tank / consumption * 100, | |
consumptionTarget: nil) | |
} | |
} | |
let badTruck = Engine(tank: 100, consumption: 8, distance: 250, consumptionTarget: nil) | |
let goodTruck = Engine(tank: 500, consumption: 20, distance: 250, consumptionTarget: nil) | |
let bestTruck = badTruck+++goodTruck | |
print("The best truck is \(bestTruck)") | |
/* | |
The best truck is Engine(tank: 500.0, consumption: 8.0, distance: 6250.0, consumptionTarget: nil) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment