Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Minimally changing combinations

by tybalt89 (Parson)
on Jun 28, 2017 at 13:54 UTC ( #1193779=note: print w/replies, xml ) Need Help??


in reply to Minimally changing combinations

What do you need a module for?

#!/usr/bin/perl -l # http://perlmonks.org/?node_id=1193761 use strict; use warnings; my @list1 = qw( a b c ); my @list2 = qw( 1 2 ); my $reverse = 0; my @combinations = map { my $left = $_; map "$left $_", $reverse++ % 2 ? reverse @list2 : @list2 } @list1; print for @combinations;

Replies are listed 'Best First'.
Re^2: Minimally changing combinations
by Anonymous Monk on Jun 28, 2017 at 14:20 UTC
    Good point. The OP says "combination", but it appears that what he actually wants is the Cartesian product.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2019-05-22 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (140 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!