TXR Lisp:
Warmup: just get the data structure first:
$ txr -p '(comb (get-lines (open-files *args*)) 2)' file1 file2 file3
(("one" "two") ("one" "three") ("one" "four") ("one" "five") ("one" "six")
("two" "three") ("two" "four") ("two" "five") ("two" "six") ("three" "four")
("three" "five") ("three" "six") ("four" "five") ("four" "six")
("five" "six"))
Now just a matter of getting the right output format. If we catenate the pairs together and then use tprint
(implicitly via the -t
option), we are there.
First, the catenation via mapping through cat-str
:
$ txr -p '[mapcar cat-str (comb (get-lines (open-files *args*)) 2)]' file1 file2 file3
("onetwo" "onethree" "onefour" "onefive" "onesix" "twothree" "twofour"
"twofive" "twosix" "threefour" "threefive" "threesix" "fourfive"
"foursix" "fivesix")
OK, we have the right data. Now just use tprint
function (-t
) instead of prinl
(-p
):
$ txr -t '[mapcar cat-str (comb (get-lines (open-files *args*)) 2)]' file1 file2 file3
onetwo
onethree
onefour
onefive
onesix
twothree
twofour
twofive
twosix
threefour
threefive
threesix
fourfive
foursix
fivesix
Finally, we read the question again and do permutations instead of combinations with perm
rather than comb
, as required:
$ txr -t '[mapcar cat-str (perm (get-lines (open-files *args*)) 2)]' file1 file2 file3
onetwo
onethree
onefour
onefive
onesix
twoone
twothree
twofour
twofive
twosix
threeone
threetwo
threefour
threefive
threesix
fourone
fourtwo
fourthree
fourfive
foursix
fiveone
fivetwo
fivethree
fivefour
fivesix
sixone
sixtwo
sixthree
sixfour
sixfive
3362 3362 19820 total
– mpla_mpla May 31 '16 at 12:16wc
, we're not dealing with huge files, so execution speed and array size limits won't much matter in this instance. Assuming the sample output above is correct then it's a permutation without repitition, with "n!/(n-r)!" items. – agc May 31 '16 at 15:54set
command to hold an array of items;set
is command line based, and is limited to a hair less thangetconf ARG_MAX
bytes, (on my system, that's about 2 megs). Since the OP's data is only 20K, (i.e. 1% of 2M),set
is good enough. – agc May 31 '16 at 16:36