Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: cross combinations

by chas (Priest)
on Oct 29, 2005 at 06:31 UTC ( #503831=note: print w/ replies, xml ) Need Help??


in reply to cross combinations

Just a remark: It has been discussed on PM in the past that the glob function will do most of the work in forming a cartesian product (I don't remember exactly where, though...) So, for example,

@a=map {split //} glob "{1,2}{3,4}"; while(@a){$x=shift @a;$y=shift @a;print "{$x,$y} "};
and you can clearly write functions like "cross" by formatting the output to taste.
(Not that this is more efficient than other solutions presented...probably isn't.)
chas


Comment on Re: cross combinations
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (14)
As of 2015-07-31 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (277 votes), past polls