Running Swift Algorithm solutions in playground

Was looking to do the LCS in Swift in a playground and found this:

So I cut-n-paste into a playground and it doesn’t work.

Playgrounds doesn’t like the self.

Is there a playgrounds ready version of this?

Here is the source code for lcsLength(_:); this lives in an extension on String

For example:

import UIKit

extension String {
    func dostuff() {
        print(self + " world")  //self is the String object that is calling this method
    }
}


let str = "hello"
str.dostuff()

--output:--
hello world

See extensions in Swift for more info.

Update: Looks like the answer posted is wrong.

It says the answer is 3 to “ABCBX” and “ABDCAB”, but my Python code says 4.

Never mind, figured it out.

Great selection of algorithms!

This topic was automatically closed after 166 days. New replies are no longer allowed.