Just use sequence comparison.
The documentation could explain this better, but it turns out (with an assumption about your intention) this is really trivial to do with Anydice's built in comparisons. In the documentation about sequences:
Compared to a sequence
The sequences are compared number by number, from left to right, resulting in either a 1 or a 0.
Experimentation shows this means it actually iterates through the sequences, comparing the Nth value of the first to the Nth value of the other. If we have two sequences, A and B, then A > B iterates through the sequence:
returns 1 if the Nth value of A is greater than the Nth value of B
returns 0 if the Nth value of A is less than the Nth value of B
goes on to the N+1th value if they are equal
It also returns 1 if B runs out of elements before A or 0 if A runs out of elements before or at the same time as B.
So if you compare the sequences:
{6,4,3,2} > {6,4,2,1} : 1
{6,4,3,2} > {6,4,3,3} : 0
{6,4,3,2} > {6,4,3} : 1
{6,4,3} > {6,4,3,1} : 0
{6,6,5} > {6,5,5,1} : 1
You can do this sort of comparison with dice if you cast them to sequences using a function before you compare them.
function: compare ATTACK:s to DEFENCE:s {
result: ATTACK > DEFENCE
}
output [compare 4d6 to 3d6]
When the function compare ATTACK to DEFENCE is invoked, the ATTACK:s and DEFENCE:s in the declaration convert whatever arguments are provided into a sequence. When a dice pool is converted into a sequence, it becomes a sequence representing the results of rolling that dice pool, sorted from high to low (and the function is invoked once for every possible result of the roll and the results statistics'd together).
This program takes dice pools and does a bit of sequence comparison to tell you which one wins under these circumstances. This does assume that your rule is that 6,6,5 beats 6,5,5, i.e. that dice cancel each other out on a 1:1 basis; if you intended differently, this becomes much more complex to describe and Anydice starts to not be very efficient.