Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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.

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-05-21 21:21 GMT
Find Nodes?
    Voting Booth?