Last active
March 28, 2016 12:12
-
-
Save neelsmith/393dbe8a56e5eb1bd1c6 to your computer and use it in GitHub Desktop.
Print longest common subsequence of two strings of characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Compute Longest Common Subsequence of two strings of characters, | |
* and print it to standard output. | |
* | |
* Example: | |
* | |
* groovy lcs.groovy 'Dr Rock-and-Roll Star' 'Doctor Rock Star' | |
* | |
* prints | |
* | |
* Dr Rock Star | |
* | |
*/ | |
@GrabResolver(name='beta', root='http://beta.hpcc.uh.edu/nexus/content/repositories/releases') | |
@Grab(group='edu.holycross.shot', module='listutils', version='1.1.0') | |
import edu.holycross.shot.listutils.ListDiff | |
String usage = "Usage: groovy lcs.groovy STRING1 STRING2" | |
if (args.size() != 2) { | |
System.err.println usage | |
System.exit(-1) | |
} | |
ListDiff ldiff = new ListDiff(args[0],args[1]) | |
println ldiff.lcs.join("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment