Skip to content

Instantly share code, notes, and snippets.

@bolivarbryan
Created July 28, 2020 00:32
Show Gist options
  • Save bolivarbryan/73263450e00141be9ec75a97739c231e to your computer and use it in GitHub Desktop.
Save bolivarbryan/73263450e00141be9ec75a97739c231e to your computer and use it in GitHub Desktop.
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