Created
July 28, 2020 00:32
-
-
Save bolivarbryan/73263450e00141be9ec75a97739c231e 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
import UIKit | |
enum State { | |
case go | |
case stay | |
} | |
func calculateGroupCompatibility(groupName: String, shipName: String) -> State { | |
var dict: [String: Int] = [:] | |
"abcdefghijklmnopqrstuvwxyz" | |
.enumerated() | |
.map { (index, value) -> (String, Int) in | |
return (String(value), index) | |
} | |
.forEach { pair in | |
dict[pair.0] = pair.1 + 1 | |
} | |
var totalGroup = 1 | |
var totalShip = 1 | |
groupName | |
.map { String($0) } | |
.forEach { item in | |
totalGroup = dict[item]! * totalGroup | |
} | |
shipName | |
.map { String($0) } | |
.forEach { item in | |
totalShip = dict[item]! * totalShip | |
} | |
return groupName == shipName ? .go : .stay | |
} | |
calculateGroupCompatibility(groupName: "caca", shipName: "caca") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment