Skip to content

Instantly share code, notes, and snippets.

@kongtomorrow
Last active August 29, 2015 14:11
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 kongtomorrow/ebc9d04c938c999a9ff5 to your computer and use it in GitHub Desktop.
Save kongtomorrow/ebc9d04c938c999a9ff5 to your computer and use it in GitHub Desktop.
var s : NSString = String(count: n, repeatedValue: Character("."))
let r = NSRegularExpression(pattern: "^(..+?)\\1+$", options: nil, error: nil)!
var l = s.length
var re = [Int]()
while let m = r.firstMatchInString(s, options:nil, range:NSRange(0..<l)) {
let p = m.rangeAtIndex(1).length
re += [p]
l /= p
s = s.substringToIndex(l)
}
re += [l]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment