On Thu, 8 Sep 2011, tim vets wrote:
what's the best way to 'interlace' two lists, i.e. turn: 1 2 3 4 and 5 6 7 8 into 1 5 2 6 3 7 4 8 ?
It's usually called interleaving.
If they are all floats, the fastest is something like this :
[list prepend 1 4 f #] | [#join 0]---------------[list prepend 1 4 f #] | [#transpose] | [#to_l]
where the 1 4 f # prefix means you want to make a grid of 1 row and 4 columns of floats. Then in contact with grid-inlets, those prefixed lists become grids of 1 by 4.
[#join] joins them by the dimension 0, which makes a single grid of (1+1=2) rows by 4 columns.
[transpose] swaps the first two dimensions, which makes a grid of 4 rows by 2 columns.
[#to_l] makes a list of 8 elements, row after row.
Of course you can instead use a [list append] and messagebox containing :
$1 $5 $2 $6 $3 $7 $4 $8
and in that particular case, it's more efficient, but the GridFlow solution works for any list length, and is probably more efficient for big lists...
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC