Skip to content

Instantly share code, notes, and snippets.

@craigomac
Created April 28, 2016 13:02
Show Gist options
  • Save craigomac/2f88d0949c0cdd64df01d6dd32e1628e to your computer and use it in GitHub Desktop.
Save craigomac/2f88d0949c0cdd64df01d6dd32e1628e to your computer and use it in GitHub Desktop.
Emoji Sums
struct Emoji {
var character: String
}
let emojiSums = [
"😐": ["😊", "πŸ˜’"],
"πŸ˜€": ["😊", "😊"],
"😭": ["πŸ˜’", "πŸ˜’"],
"πŸ–": ["πŸ”", "πŸ”₯"]
].map({(sum: $0, parts: $1.sorted())})
func + (left: Emoji, right: Emoji) -> Emoji {
let characters = [left.character, right.character].sorted()
for (sum, parts) in emojiSums {
if parts == characters {
return Emoji(character: sum)
}
}
return "😡"
}
extension Emoji: StringLiteralConvertible, CustomStringConvertible {
var description: String {
get {
return character
}
}
init(stringLiteral value: String) {
self.character = value
}
init(extendedGraphemeClusterLiteral value: String) {
self.character = value
}
init(unicodeScalarLiteral value: String) {
self.character = value
}
}
let happy:Emoji = "😊"
let sad:Emoji = "πŸ˜’"
let chicken:Emoji = "πŸ”"
let fire:Emoji = "πŸ”₯"
print(happy + sad)
print(happy + happy)
print(sad + sad)
print(chicken + fire)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment