Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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.

Comment on Algorithm help
Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2015-11-29 05:23 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (747 votes), past polls