Skip to content

Instantly share code, notes, and snippets.

@rayfix
Created February 12, 2017 22:16
Show Gist options
  • Save rayfix/4cc72bc19a59407bd32f3b19d03cbeb0 to your computer and use it in GitHub Desktop.
Save rayfix/4cc72bc19a59407bd32f3b19d03cbeb0 to your computer and use it in GitHub Desktop.
let str = "acxz"
func isFunny(_ s: AnySequence<UInt8>) -> Bool {
let n1: [Int] = zip(s.dropFirst(), s).map { Int($0)-Int($1) }
let n2: [Int] = zip(s.reversed().dropFirst(), s.reversed()).map { Int($1)-Int($0) }
return n1 == n2
}
isFunny(AnySequence(str.utf8))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment