Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spoilers!
-- http://codegolf.stackexchange.com/questions/2862/shortest-lexicographically-smallest-generating-string/2868#2868
import Data.List
f z q=concat$replicate(length z)q
main=interact(\z->minimum$filter(\q->isInfixOf z$f z q)$sort$filter(not.null)$inits=<<tails z)
-- Original version in 91 chars.
import Data.List
main=interact(\z->minimum$filter(\q->isInfixOf z$q++q++q)$inits=<<tails z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment