This program implements the Key Word In Context (KWIC) index system (in 98 bytes). This system accepts a sequence of lines of text and circularly shifts each line by repeatedly removing the first word and appending it to the end of the line. The KWIC system then outputs a listing of all circular shifts of all lines, in sorted order.sub f{@a=();for(@_){push @_,shift;push @a,"@_"}@a}push@_,f split while + <>;print join "\n",sort @_
Run it with perl kwic.pl filename, where filename contains the lines you want to apply the KWIC system to.
This can probably be done more compactly... anybody out there got a shorter solution?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Key Word In Context system (golf, anyone)?
by danger (Priest) on Mar 07, 2001 at 10:26 UTC | |
Re: Key Word In Context system (golf, anyone)?
by btrott (Parson) on Mar 07, 2001 at 09:49 UTC | |
Re: Key Word In Context system (golf, anyone)?
by jmcnamara (Monsignor) on Mar 27, 2001 at 17:34 UTC |
Back to
Obfuscated Code