Skip to content

Instantly share code, notes, and snippets.

@keitaito
Last active January 19, 2017 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keitaito/7123c5b76a7d2b8fa067bf9123089dfc to your computer and use it in GitHub Desktop.
Save keitaito/7123c5b76a7d2b8fa067bf9123089dfc to your computer and use it in GitHub Desktop.
Solution for The Love Letter Mystery in HackerRank
// 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