Created
August 5, 2012 17:33
-
-
Save 5outh/3266149 to your computer and use it in GitHub Desktop.
Golf w/ comments
This file contains hidden or 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
import Data.List -- gets us the function "intersect" | |
import System.Environment -- gets us the function "getArgs" | |
f=concat.r -- calls "r" on some input and flattens the results (concat) | |
{- The function "r" takes a list of elements and produces all of it's possible sublists. | |
Base case: If the input list is empty, return an empty list containing a single empty list. -} | |
r []=[[]] -- base case for "r" | |
r s= (scanr(:)[]s) {- recursively build substrings from the list "s" | |
and push them to an empty list -} | |
: -- Append the list we just built to... | |
(r$init s) -- "r" called on the first n-1 elements of of the current list "s" | |
g [a,b]=snd.maximum. -- finds the maximum by the length of strings | |
map(\x->(length x, x)) -- groups lists into tuples of their lengths and the list | |
$intersect(f a)(f b) -- The intersection* of "f" called on a, and "f" called on b | |
main= getArgs >>= -- get the command line arguments as a list ["firstString", "secondString"] | |
\z-> print.g$z -- bind the argument list (z) to print "g" called on z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment