Topological Sorting by fox

main=interact$unlines.f.map(span(':'/=)).lines
f x=x#[]
[]#_=[]
(w@(x,y):z)#v|any(`elem`(map fst$v++z))$words y=z#(v++[w])|0<1=x:f(v++z)

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page