Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Algorithm help

by Anonymous Monk
on Sep 19, 2000 at 16:19 UTC ( #33082=note: print w/ replies, xml ) Need Help??


in reply to Search Algorithm

I need a solution for a problem I'm having. I have two fields. A user will be able to enter words separated by spaces in both fields. I need to extract all the words and create a list of words. for example if the user was to enter: apples oranges pears the program will output apples applesoranges applespears oranges orangesapples orangespears pears pearsapples pearsoranges etc and the list goes on. I do not have telnet so the abigal package will not help me. Please e-mail me with a solution is someone is willing to help. webmaster@simplesoftware.net


Comment on Algorithm help
Re: Algorithm help
by Anonymous Monk on Jan 09, 2001 at 22:34 UTC
    @fruit=qw(apples oranges pears); for $f0 (@fruit){ for $f1( "",@fruit ){ print "$f0$f1\n" unless $f0 eq $f1; }}

      Here's the same thing, except using nested maps. Is there a way to do this in just one pass?

      my @fruit = qw/ apples oranges pears /; my @salad = mix_up( @fruit ); print join(', ', @salad), "\n"; sub mix_up { return map { my $tmp=$_; map { $tmp eq $_ ? $_ : "$tmp$_" } @_; } +@_; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (14)
As of 2014-07-11 19:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (235 votes), past polls