This challenge is based on a problem described in D. Parnas, On the criteria to be used in decomposing systems into modules, and elaborated upon in J. Morris, Real Programming in Functional Languages.
Write a program or function which takes a list of book titles from stdin
or as an argument, in a reasonable, convenient format for your language. For example,
Green Sleeves
Time Was Lost
or
("Green Sleeves";"Time Was Lost")
Return or print to stdout
an alphabetized list of the keywords, showing their context within the original titles by enclosing each keyword in angle braces (<
and >
). As with input, output can be in a reasonable format which is convenient for your language- newline-separated lines, a list of strings, etc:
<Green> Sleeves
Time Was <Lost>
Green <Sleeves>
<Time> Was Lost
Time <Was> Lost
Titles will consist of a series of keywords separated by a single space. Keywords will contain only alphabetic characters. Keywords are to be sorted lexicographically. Titles will be unique, and keywords will be unique within each title but the same keyword may exist in several titles. If a keyword exists in more than one title, the output should list each appearance in an arbitrary order. For example, given this input:
A Dugong
A Proboscis
A valid output would be either:
<A> Proboscis
<A> Dugong
A <Dugong>
A <Proboscis>
Or:
<A> Dugong
<A> Proboscis
A <Dugong>
A <Proboscis>
This is code-golf- the winner is the shortest solution in bytes. Standard loopholes are disallowed.