Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Subphrases from a phrase

by BrowserUk (Patriarch)
on Aug 10, 2005 at 00:52 UTC ( [id://482479]=note: print w/replies, xml ) Need Help??


in reply to Subphrases from a phrase

You missed one combination, "camel book":

#! perl -slw use strict; use List::Util qw[ sum ]; sub Cnr{ my( $n, @r ) = shift; return [] unless $n--; for my $x ( 0 .. ($#_ - $n) ) { push @r, map{ [ $_[$x], @$_ ] } Cnr( $n, @_[ ($x + 1) .. $#_ ] ); } return @r; } our $N ||= 0; print map "@$_\n", Cnr( $N, @ARGV ) and exit if $N; print map{ "@$_\n" } Cnr( $_, @ARGV ) for 1 .. @ARGV; __END__ P:\test>cnr camel perl book camel perl book camel perl camel book perl book camel perl book

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: Subphrases from a phrase
by graff (Chancellor) on Aug 10, 2005 at 01:49 UTC
    It's entirely possible that the OP does not want "camel book" to be among the outputs in this example -- the task may be limited to all possible substrings consisting of single words or two or more adjacent words in sequence.

      Good point. I hadn't looked at it that way.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://482479]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found