redribben

Palin

Dec 12th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.87 KB | None | 0 0
  1. func confuser() {
  2.     if let fileURL = Bundle.main.url(forResource: "screams", withExtension: nil) {
  3.         do {
  4.             let contents = try String(contentsOf: fileURL, encoding: String.Encoding.utf8)
  5.             let words = contents.components(separatedBy: "\n")
  6.             for word in words {
  7.                 let line = word.components(separatedBy: .punctuationCharacters)
  8.                     .joined().components(separatedBy: .whitespaces)
  9.                     .joined().lowercased()
  10.                 let enil = String(line.reversed())
  11.                 if (word == "") { continue; }
  12.                 if line == enil {
  13.                     print("AY|" + word);
  14.                 } else {
  15.                     print("NAY|" + enil);
  16.                 }
  17.             }
  18.         } catch {  print("Error: \(error.localizedDescription)") }
  19.     } else { print("No such file URL.") }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment