Last active
January 19, 2017 07:43
-
-
Save keitaito/7123c5b76a7d2b8fa067bf9123089dfc to your computer and use it in GitHub Desktop.
Solution for The Love Letter Mystery in HackerRank
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
// https://www.hackerrank.com/challenges/the-love-letter-mystery | |
let t = Int(readLine()!)! | |
var inputs = [String]() | |
for i in 0..<t { | |
let string = readLine()! | |
inputs.append(string) | |
} | |
for string in inputs { | |
var copy = string | |
var reversed = String(string.characters.reversed()) | |
let cValues = copy.unicodeScalars.map { Int($0.value) } | |
let rValues = reversed.unicodeScalars.map { Int($0.value) } | |
var count = 0 | |
for i in 0..<cValues.count { | |
if cValues[i] < rValues[i] { | |
count += rValues[i] - cValues[i] | |
} | |
} | |
print(count) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment