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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Subphrases from a phrase
by graff (Chancellor) on Aug 10, 2005 at 01:49 UTC | |
by BrowserUk (Patriarch) on Aug 10, 2005 at 02:01 UTC |