Created
May 27, 2015 14:30
-
-
Save fcanas/9f05148044951705945f to your computer and use it in GitHub Desktop.
your swift ride is here
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
func encode(name :String) -> Int { | |
return reduce(map(name.unicodeScalars) { Int($0.value) - 64 }, 1, *) % 47 | |
} | |
func ride(group: String, comet: String) -> String { | |
return encode(group) == encode(comet) ? "GO" : "STAY" | |
} | |
let testData = [ | |
("COMETQ","HVNGAT","GO"), | |
("STARAB","USACO","STAY"), | |
("EARTH","LEFTB","GO"), | |
("PULSAR","VENUS","STAY"), | |
("KANSAS","UTAH","STAY"), | |
("APPLE","URSA","GO"), | |
("MSFT","MARS","STAY"), | |
("PLUTO","BKHOLE","STAY"), | |
("COWSBC","RIGHT","GO"), | |
("DRKMTR","SNIKER","STAY")] | |
func testRide() -> String { | |
for testCase in testData { | |
if ride(testCase.0, testCase.1) != testCase.2 { | |
return "Fail: Group \(testCase.0) and comet \(testCase.1) should \(testCase.2)" | |
} | |
} | |
return "pass" | |
} | |
let testResult = testRide() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment