Created
April 28, 2016 13:02
-
-
Save craigomac/2f88d0949c0cdd64df01d6dd32e1628e to your computer and use it in GitHub Desktop.
Emoji Sums
This file contains 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
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