tcl - Print Cartesian product of two list, without nested foreach -



tcl - Print Cartesian product of two list, without nested foreach -

i need calculate cartesian product of 2 lists.

my list contains big number of elements, nested foreach not thought in case.

anything else, can used there?

you might able work on values while it's beingness set together. it's hard without @ to the lowest degree snapshot of construction you're working with. here's simple example.

the proc doesn't homecoming matrix work on points in matrix.

proc my_cartesian {a b} { set len_a [llength $a] set len_b [llength $b] set len [expr $len_a * $len_b] set y 0 {set 0} {$i < $len} {incr i} { set x [expr $i % $len_a] if {$x == 0 && $i != 0} { incr y } set px [lindex $a $x] set py [lindex $b $y] # code puts "$px, $py" } } my_cartesian {a b c} {1 2 3}

output:

a, 1 b, 1 c, 1 a, 2 b, 2 c, 2 a, 3 b, 3 c, 3

tcl cartesian-product

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -