redribben icon

Palin

redribben | PRO | 12/13/17 01:43:51 AM UTC | 0 ⭐ | 380 👁️ | Never ⏰ | []
Swift |

870 B

|

None

|

0 👍

/

0 👎

func confuser() {
    if let fileURL = Bundle.main.url(forResource: "screams", withExtension: nil) {
        do {
            let contents = try String(contentsOf: fileURL, encoding: String.Encoding.utf8)
            let words = contents.components(separatedBy: "\n")
            for word in words {
                let line = word.components(separatedBy: .punctuationCharacters)
                    .joined().components(separatedBy: .whitespaces)
                    .joined().lowercased()
                let enil = String(line.reversed())
                if (word == "") { continue; }
                if line == enil {
                    print("AY|" + word);
                } else {
                    print("NAY|" + enil);
                }
            }
        } catch {  print("Error: \(error.localizedDescription)") }
    } else { print("No such file URL.") }
}

Comments