Jump to content

Combination Function Result (is it rigth ?)


Recommended Posts

Dear All, 

 

Recently, I used the function combination and got some strange result

 

I did this

 

(combination 3 '(0 1 2 3 4 5))

 

I got this result - 60 combinations

 

(0 1 2) (0 1 3) (0 1 4) (0 1 5) (0 2 3) (0 2 4) (0 2 5) (0 3 4) (0 3 5) (0 4 5) (1 2 3) (1 2 4) (1 2 5) (1 3 4) (1 3 5) (1 4 5)(2 3 4) (2 3 5) (2 4 5) (3 4 5)(5 0 1) (5 0 2) (5 0 3) (5 0 4) (5 1 2) (5 1 3) (5 1 4) (5 2 3) (5 2 4) (5 3 4) ,(4 5 0) (4 5 1) (4 5 2) (4 5 3) (4 0 1) (4 0 2) (4 0 3) (4 1 2) (4 1 3) (4 2 3)(3 4 0) (3 4 1) (3 4 2) (3 5 0) (3 5 1) (3 5 2) (3 0 1) (3 0 2) (3 1 2) (2 3 0) (2 3 1) (2 4 0) (2 4 1) (2 5 0) (2 5 1) (2 0 1) (1 2 0) (1 3 0) (1 4 0) (1 5 0)

 

There is something I did not get ?

 

Best,

Julio

 

The expected result should be 6 x 5 x 4 = 120

 

 

Like this...

 

012
013
014
015
021
023
024
025
031
032
034
035
041
042
043
045
051
052
053
054
105
102
103
104
125
120
123
124
135
130
132
134
145
140
142
143
154
150
152
153
204
205
201
203
214
215
210
213
234
235
230
231
243
245
240
241
253
254
250
251
302
304
305
301
312
314
315
310
321
324
325
320
341
342
345
340
351
352
354
350
401
402
403
405
410
412
413
415
420
421
423
425
430
431
432
435
450
451
452
453
504
501
502
503
514
510
512
513
524
520
521
523
534
530
531
532
543
540
541
542

Link to comment
Share on other sites

According to the definition of the function:

COMBINATION will return a list of all the combinations N elements in length from a list.

 

There is something strange...

For example:

 

(combination 3 '(0 1 2)) gives

((0 1 2) (0 2 1) (1 0 2) (1 2 0) (2 0 1) (2 1 0))

and violate what the "unique combination" state you mentioned, since 0 1 2 is also (0 2 1)

Looks like permutation...

 

I´m looking for all n-permutations of a larger set, like

3 element permutations from a group of 6 elements (0 1 2 3 4 5).

 

Maybe having the possibility of choosing the cardinality of permutations...

 

Something like (permute 3 '(0 1 2 3 4 5)) should give the result I mentioned before (120 possbilities)

 

Best,

Julio

13 hours ago, JulioHerrlein said:

012
013
014
015
021
023
024
025
031
032
034
035
041
042
043
045
051
052
053
054
105
102
103
104
125
120
123
124
135
130
132
134
145
140
142
143
154
150
152
153
204
205
201
203
214
215
210
213
234
235
230
231
243
245
240
241
253
254
250
251
302
304
305
301
312
314
315
310
321
324
325
320
341
342
345
340
351
352
354
350
401
402
403
405
410
412
413
415
420
421
423
425
430
431
432
435
450
451
452
453
504
501
502
503
514
510
512
513
524
520
521
523
534
530
531
532
543
540
541
542

 

Link to comment
Share on other sites

I will change the combination to the definition and will add an additional function combination-permute which will return what you are looking for:

((0 1 2) (0 1 3) (0 1 4) (0 1 5) (0 2 1) (0 2 3) (0 2 4) (0 2 5) (0 3 1) (0 3 2)
 (0 3 4) (0 3 5) (0 4 1) (0 4 2) (0 4 3) (0 4 5) (0 5 1) (0 5 2) (0 5 3) (0 5 4
 (1 0 2) (1 0 3) (1 0 4) (1 0 5) (1 2 0) (1 2 3) (1 2 4) (1 2 5) (1 3 0) (1 3 2)
 (1 3 4) (1 3 5) (1 4 0) (1 4 2) (1 4 3) (1 4 5) (1 5 0) (1 5 2) (1 5 3) (1 5 4)
 (2 0 1) (2 0 3) (2 0 4) (2 0 5) (2 1 0) (2 1 3) (2 1 4) (2 1 5) (2 3 0) (2 3 1)
 (2 3 4) (2 3 5) (2 4 0) (2 4 1) (2 4 3) (2 4 5) (2 5 0) (2 5 1) (2 5 3) (2 5 4)
 (3 0 1) (3 0 2) (3 0 4) (3 0 5) (3 1 0) (3 1 2) (3 1 4) (3 1 5) (3 2 0) (3 2 1)
 (3 2 4) (3 2 5) (3 4 0) (3 4 1) (3 4 2) (3 4 5) (3 5 0) (3 5 1) (3 5 2) (3 5 4)
 (4 0 1) (4 0 2) (4 0 3) (4 0 5) (4 1 0) (4 1 2) (4 1 3) (4 1 5) (4 2 0) (4 2 1)
 (4 2 3) (4 2 5) (4 3 0) (4 3 1) (4 3 2) (4 3 5) (4 5 0) (4 5 1) (4 5 2) (4 5 3)
 (5 0 1) (5 0 2) (5 0 3) (5 0 4) (5 1 0) (5 1 2) (5 1 3) (5 1 4) (5 2 0) (5 2 1)
 (5 2 3) (5 2 4) (5 3 0) (5 3 1) (5 3 2) (5 3 4) (5 4 0) (5 4 1) (5 4 2) (5 4 3))

 

The result of (combination 3 '(0 1 2 3 4 5)) will be:
 

((0 1 2) (0 1 3) (0 1 4) (0 1 5) (0 1 6) (0 2 3) (0 2 4) (0 2 5) (0 2 6) (0 3 4)
 (0 3 5) (0 3 6) (0 4 5) (0 4 6) (0 5 6) (1 2 3) (1 2 4) (1 2 5) (1 2 6) (1 3 4)
 (1 3 5) (1 3 6) (1 4 5) (1 4 6) (1 5 6) (2 3 4) (2 3 5) (2 3 6) (2 4 5) (2 4 6)
 (2 5 6) (3 4 5) (3 4 6) (3 5 6) (4 5 6))

 

Link to comment
Share on other sites

Thanks, Janusz

 

Here is the breakdown of the equivalent permutations for the example

 

012 021 102 120 201 210
013 031 103 130 301 310
014 041 104 140 401 410
015 051 105 150 501 510
023 032 230 203 302 320
024 042 204 240 402 420
025 052 205 250 502 520
034 043 304 340 403 430
035 053 305 350 503 530
045 405 450 504 540 054
125 152 215 251 512 521
123 132 213 231 312 321
124 142 214 241 412 421
135 153 315 351 513 531
134 143 314 341 413 431
145 154 415 451 514 541
234 243 324 342 423 432
235 253 325 352 523 532
245 254 425 452 524 542
345 354 435 453 534 543

 

 

The first column is the unique "seed" that gives the other permutations

Just the seeds

 

012 
013 
014 
015 
023 
024 
025 
034 
035 
045 
125 
123
124
135
134
145
234
235 
245 
345 

Seeds above, arranged as complementary sets


012,345 
013,245  
014,235
015,234 
023,145 
024,135 
025,134
034,125 
035,124 
045,123 

Link to comment
Share on other sites

Done:

(combination 3 '(0 1 2 3 4 5))
=> ((0 1 2) (0 1 3) (0 1 4) (0 1 5) (0 2 3) (0 2 4) (0 2 5)
    (0 3 4) (0 3 5) (0 4 5) (1 2 3) (1 2 4) (1 2 5) (1 3 4)
    (1 3 5) (1 4 5) (2 3 4) (2 3 5) (2 4 5) (3 4 5))
    
(combination 3 '(0 1 2 3 4 5) :permute t)
=> ((0 1 2) (0 2 1) (1 0 2) (1 2 0) (2 0 1) (2 1 0) (0 1 3)
    (0 3 1) (1 0 3) (1 3 0) (3 0 1) (3 1 0) (0 1 4) (0 4 1)
    (1 0 4) (1 4 0) (4 0 1) (4 1 0) (0 1 5) (0 5 1) (1 0 5)
    (1 5 0) (5 0 1) (5 1 0) (0 2 3) (0 3 2) (2 0 3) (2 3 0)
    (3 0 2) (3 2 0) (0 2 4) (0 4 2) (2 0 4) (2 4 0) (4 0 2)
    (4 2 0) (0 2 5) (0 5 2) (2 0 5) (2 5 0) (5 0 2) (5 2 0)
    (0 3 4) (0 4 3) (3 0 4) (3 4 0) (4 0 3) (4 3 0) (0 3 5)
    (0 5 3) (3 0 5) (3 5 0) (5 0 3) (5 3 0) (0 4 5) (0 5 4)
    (4 0 5) (4 5 0) (5 0 4) (5 4 0) (1 2 3) (1 3 2) (2 1 3)
    (2 3 1) (3 1 2) (3 2 1) (1 2 4) (1 4 2) (2 1 4) (2 4 1)
    (4 1 2) (4 2 1) (1 2 5) (1 5 2) (2 1 5) (2 5 1) (5 1 2)
    (5 2 1) (1 3 4) (1 4 3) (3 1 4) (3 4 1) (4 1 3) (4 3 1)
    (1 3 5) (1 5 3) (3 1 5) (3 5 1) (5 1 3) (5 3 1) (1 4 5)
    (1 5 4) (4 1 5) (4 5 1) (5 1 4) (5 4 1) (2 3 4) (2 4 3)
    (3 2 4) (3 4 2) (4 2 3) (4 3 2) (2 3 5) (2 5 3) (3 2 5)
    (3 5 2) (5 2 3) (5 3 2) (2 4 5) (2 5 4) (4 2 5) (4 5 2)
    (5 2 4) (5 4 2) (3 4 5) (3 5 4) (4 3 5) (4 5 3) (5 3 4)
    (5 4 3))


 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy