Home > Mobile >  Combine a combination of n size with another combination from different size into a single output
Combine a combination of n size with another combination from different size into a single output

Time:10-12

A few years ago, a relative played the lottery and got 4 out 6 numbers in one play and 2 out of 6 in the other, both plays were on the same ticket. Just for curiosity's sake, assuming that one could go back in time with that knowledge and play every combination from the play with 4 out of 6 numbers with every combination from 2 out of 6 numbers which totals 225 plays, how would one output everything in one line?

I can get the 15 combinations from 4/6 with

combn(c(16, 28, 5, 9, 13, 26), 4)

and another 15 from 2/6 with

comb(c(32, 29, 14, 6, 3, 14), 2)

I'd like to get all these combined into a single output which should output 225 combinations.

CodePudding user response:

I imagine there are lots of ways to solve this problem. One potential solution is to transform the 'picks' into dataframes and merge them:

library(tidyverse)
options(max.print = 2000)

A <- t(combn(c(16, 28, 5, 9, 13, 26), 4))
B <- t(combn(c(32, 29, 14, 6, 3, 14), 2))

A_df <- as.data.frame(A)
names(A_df) <- paste("x4.of.6.", 1:4, sep = "")

B_df <- as.data.frame(B)
names(B_df) <- paste("x2.of.6.", 1:2, sep = "")

merge(B_df, A_df)
#>     x2.of.6.1 x2.of.6.2 x4.of.6.1 x4.of.6.2 x4.of.6.3 x4.of.6.4
#> 1          32        29        16        28         5         9
#> 2          32        14        16        28         5         9
#> 3          32         6        16        28         5         9
#> 4          32         3        16        28         5         9
#> 5          32        14        16        28         5         9
#> 6          29        14        16        28         5         9
#> 7          29         6        16        28         5         9
#> 8          29         3        16        28         5         9
#> 9          29        14        16        28         5         9
#> 10         14         6        16        28         5         9
#> 11         14         3        16        28         5         9
#> 12         14        14        16        28         5         9
#> 13          6         3        16        28         5         9
#> 14          6        14        16        28         5         9
#> 15          3        14        16        28         5         9
#> 16         32        29        16        28         5        13
#> 17         32        14        16        28         5        13
#> 18         32         6        16        28         5        13
#> 19         32         3        16        28         5        13
#> 20         32        14        16        28         5        13
#> 21         29        14        16        28         5        13
#> 22         29         6        16        28         5        13
#> 23         29         3        16        28         5        13
#> 24         29        14        16        28         5        13
#> 25         14         6        16        28         5        13
#> 26         14         3        16        28         5        13
#> 27         14        14        16        28         5        13
#> 28          6         3        16        28         5        13
#> 29          6        14        16        28         5        13
#> 30          3        14        16        28         5        13
#> 31         32        29        16        28         5        26
#> 32         32        14        16        28         5        26
#> 33         32         6        16        28         5        26
#> 34         32         3        16        28         5        26
#> 35         32        14        16        28         5        26
#> 36         29        14        16        28         5        26
#> 37         29         6        16        28         5        26
#> 38         29         3        16        28         5        26
#> 39         29        14        16        28         5        26
#> 40         14         6        16        28         5        26
#> 41         14         3        16        28         5        26
#> 42         14        14        16        28         5        26
#> 43          6         3        16        28         5        26
#> 44          6        14        16        28         5        26
#> 45          3        14        16        28         5        26
#> 46         32        29        16        28         9        13
#> 47         32        14        16        28         9        13
#> 48         32         6        16        28         9        13
#> 49         32         3        16        28         9        13
#> 50         32        14        16        28         9        13
#> 51         29        14        16        28         9        13
#> 52         29         6        16        28         9        13
#> 53         29         3        16        28         9        13
#> 54         29        14        16        28         9        13
#> 55         14         6        16        28         9        13
#> 56         14         3        16        28         9        13
#> 57         14        14        16        28         9        13
#> 58          6         3        16        28         9        13
#> 59          6        14        16        28         9        13
#> 60          3        14        16        28         9        13
#> 61         32        29        16        28         9        26
#> 62         32        14        16        28         9        26
#> 63         32         6        16        28         9        26
#> 64         32         3        16        28         9        26
#> 65         32        14        16        28         9        26
#> 66         29        14        16        28         9        26
#> 67         29         6        16        28         9        26
#> 68         29         3        16        28         9        26
#> 69         29        14        16        28         9        26
#> 70         14         6        16        28         9        26
#> 71         14         3        16        28         9        26
#> 72         14        14        16        28         9        26
#> 73          6         3        16        28         9        26
#> 74          6        14        16        28         9        26
#> 75          3        14        16        28         9        26
#> 76         32        29        16        28        13        26
#> 77         32        14        16        28        13        26
#> 78         32         6        16        28        13        26
#> 79         32         3        16        28        13        26
#> 80         32        14        16        28        13        26
#> 81         29        14        16        28        13        26
#> 82         29         6        16        28        13        26
#> 83         29         3        16        28        13        26
#> 84         29        14        16        28        13        26
#> 85         14         6        16        28        13        26
#> 86         14         3        16        28        13        26
#> 87         14        14        16        28        13        26
#> 88          6         3        16        28        13        26
#> 89          6        14        16        28        13        26
#> 90          3        14        16        28        13        26
#> 91         32        29        16         5         9        13
#> 92         32        14        16         5         9        13
#> 93         32         6        16         5         9        13
#> 94         32         3        16         5         9        13
#> 95         32        14        16         5         9        13
#> 96         29        14        16         5         9        13
#> 97         29         6        16         5         9        13
#> 98         29         3        16         5         9        13
#> 99         29        14        16         5         9        13
#> 100        14         6        16         5         9        13
#> 101        14         3        16         5         9        13
#> 102        14        14        16         5         9        13
#> 103         6         3        16         5         9        13
#> 104         6        14        16         5         9        13
#> 105         3        14        16         5         9        13
#> 106        32        29        16         5         9        26
#> 107        32        14        16         5         9        26
#> 108        32         6        16         5         9        26
#> 109        32         3        16         5         9        26
#> 110        32        14        16         5         9        26
#> 111        29        14        16         5         9        26
#> 112        29         6        16         5         9        26
#> 113        29         3        16         5         9        26
#> 114        29        14        16         5         9        26
#> 115        14         6        16         5         9        26
#> 116        14         3        16         5         9        26
#> 117        14        14        16         5         9        26
#> 118         6         3        16         5         9        26
#> 119         6        14        16         5         9        26
#> 120         3        14        16         5         9        26
#> 121        32        29        16         5        13        26
#> 122        32        14        16         5        13        26
#> 123        32         6        16         5        13        26
#> 124        32         3        16         5        13        26
#> 125        32        14        16         5        13        26
#> 126        29        14        16         5        13        26
#> 127        29         6        16         5        13        26
#> 128        29         3        16         5        13        26
#> 129        29        14        16         5        13        26
#> 130        14         6        16         5        13        26
#> 131        14         3        16         5        13        26
#> 132        14        14        16         5        13        26
#> 133         6         3        16         5        13        26
#> 134         6        14        16         5        13        26
#> 135         3        14        16         5        13        26
#> 136        32        29        16         9        13        26
#> 137        32        14        16         9        13        26
#> 138        32         6        16         9        13        26
#> 139        32         3        16         9        13        26
#> 140        32        14        16         9        13        26
#> 141        29        14        16         9        13        26
#> 142        29         6        16         9        13        26
#> 143        29         3        16         9        13        26
#> 144        29        14        16         9        13        26
#> 145        14         6        16         9        13        26
#> 146        14         3        16         9        13        26
#> 147        14        14        16         9        13        26
#> 148         6         3        16         9        13        26
#> 149         6        14        16         9        13        26
#> 150         3        14        16         9        13        26
#> 151        32        29        28         5         9        13
#> 152        32        14        28         5         9        13
#> 153        32         6        28         5         9        13
#> 154        32         3        28         5         9        13
#> 155        32        14        28         5         9        13
#> 156        29        14        28         5         9        13
#> 157        29         6        28         5         9        13
#> 158        29         3        28         5         9        13
#> 159        29        14        28         5         9        13
#> 160        14         6        28         5         9        13
#> 161        14         3        28         5         9        13
#> 162        14        14        28         5         9        13
#> 163         6         3        28         5         9        13
#> 164         6        14        28         5         9        13
#> 165         3        14        28         5         9        13
#> 166        32        29        28         5         9        26
#> 167        32        14        28         5         9        26
#> 168        32         6        28         5         9        26
#> 169        32         3        28         5         9        26
#> 170        32        14        28         5         9        26
#> 171        29        14        28         5         9        26
#> 172        29         6        28         5         9        26
#> 173        29         3        28         5         9        26
#> 174        29        14        28         5         9        26
#> 175        14         6        28         5         9        26
#> 176        14         3        28         5         9        26
#> 177        14        14        28         5         9        26
#> 178         6         3        28         5         9        26
#> 179         6        14        28         5         9        26
#> 180         3        14        28         5         9        26
#> 181        32        29        28         5        13        26
#> 182        32        14        28         5        13        26
#> 183        32         6        28         5        13        26
#> 184        32         3        28         5        13        26
#> 185        32        14        28         5        13        26
#> 186        29        14        28         5        13        26
#> 187        29         6        28         5        13        26
#> 188        29         3        28         5        13        26
#> 189        29        14        28         5        13        26
#> 190        14         6        28         5        13        26
#> 191        14         3        28         5        13        26
#> 192        14        14        28         5        13        26
#> 193         6         3        28         5        13        26
#> 194         6        14        28         5        13        26
#> 195         3        14        28         5        13        26
#> 196        32        29        28         9        13        26
#> 197        32        14        28         9        13        26
#> 198        32         6        28         9        13        26
#> 199        32         3        28         9        13        26
#> 200        32        14        28         9        13        26
#> 201        29        14        28         9        13        26
#> 202        29         6        28         9        13        26
#> 203        29         3        28         9        13        26
#> 204        29        14        28         9        13        26
#> 205        14         6        28         9        13        26
#> 206        14         3        28         9        13        26
#> 207        14        14        28         9        13        26
#> 208         6         3        28         9        13        26
#> 209         6        14        28         9        13        26
#> 210         3        14        28         9        13        26
#> 211        32        29         5         9        13        26
#> 212        32        14         5         9        13        26
#> 213        32         6         5         9        13        26
#> 214        32         3         5         9        13        26
#> 215        32        14         5         9        13        26
#> 216        29        14         5         9        13        26
#> 217        29         6         5         9        13        26
#> 218        29         3         5         9        13        26
#> 219        29        14         5         9        13        26
#> 220        14         6         5         9        13        26
#> 221        14         3         5         9        13        26
#> 222        14        14         5         9        13        26
#> 223         6         3         5         9        13        26
#> 224         6        14         5         9        13        26
#> 225         3        14         5         9        13        26

Created on 2021-10-11 by the reprex package (v2.0.1)

Or, another potential solution:

A <- combn(c(16, 28, 5, 9, 13, 26), 4)
B <- combn(c(32, 29, 14, 6, 3, 14), 2)

for (i in seq_along(A[1,])){
  for (j in seq_along(A[1,])){
  print(c(A[,i], B[,j]))
  }
}
#> [1] 16 28  5  9 32 29
#> [1] 16 28  5  9 32 14
#> [1] 16 28  5  9 32  6
#> [1] 16 28  5  9 32  3
#> [1] 16 28  5  9 32 14
#> [1] 16 28  5  9 29 14
#> [1] 16 28  5  9 29  6
#> [1] 16 28  5  9 29  3
#> [1] 16 28  5  9 29 14
#> [1] 16 28  5  9 14  6
#> [1] 16 28  5  9 14  3
#> [1] 16 28  5  9 14 14
#> [1] 16 28  5  9  6  3
#> [1] 16 28  5  9  6 14
#> [1] 16 28  5  9  3 14
#> [1] 16 28  5 13 32 29
#> [1] 16 28  5 13 32 14
#> [1] 16 28  5 13 32  6
#> [1] 16 28  5 13 32  3
#> [1] 16 28  5 13 32 14
#> [1] 16 28  5 13 29 14
#> [1] 16 28  5 13 29  6
#> [1] 16 28  5 13 29  3
#> [1] 16 28  5 13 29 14
#> [1] 16 28  5 13 14  6
#> [1] 16 28  5 13 14  3
#> [1] 16 28  5 13 14 14
#> [1] 16 28  5 13  6  3
#> [1] 16 28  5 13  6 14
#> [1] 16 28  5 13  3 14
#> [1] 16 28  5 26 32 29
#> [1] 16 28  5 26 32 14
#> [1] 16 28  5 26 32  6
#> [1] 16 28  5 26 32  3
#> [1] 16 28  5 26 32 14
#> [1] 16 28  5 26 29 14
#> [1] 16 28  5 26 29  6
#> [1] 16 28  5 26 29  3
#> [1] 16 28  5 26 29 14
#> [1] 16 28  5 26 14  6
#> [1] 16 28  5 26 14  3
#> [1] 16 28  5 26 14 14
#> [1] 16 28  5 26  6  3
#> [1] 16 28  5 26  6 14
#> [1] 16 28  5 26  3 14
#> [1] 16 28  9 13 32 29
#> [1] 16 28  9 13 32 14
#> [1] 16 28  9 13 32  6
#> [1] 16 28  9 13 32  3
#> [1] 16 28  9 13 32 14
#> [1] 16 28  9 13 29 14
#> [1] 16 28  9 13 29  6
#> [1] 16 28  9 13 29  3
#> [1] 16 28  9 13 29 14
#> [1] 16 28  9 13 14  6
#> [1] 16 28  9 13 14  3
#> [1] 16 28  9 13 14 14
#> [1] 16 28  9 13  6  3
#> [1] 16 28  9 13  6 14
#> [1] 16 28  9 13  3 14
#> [1] 16 28  9 26 32 29
#> [1] 16 28  9 26 32 14
#> [1] 16 28  9 26 32  6
#> [1] 16 28  9 26 32  3
#> [1] 16 28  9 26 32 14
#> [1] 16 28  9 26 29 14
#> [1] 16 28  9 26 29  6
#> [1] 16 28  9 26 29  3
#> [1] 16 28  9 26 29 14
#> [1] 16 28  9 26 14  6
#> [1] 16 28  9 26 14  3
#> [1] 16 28  9 26 14 14
#> [1] 16 28  9 26  6  3
#> [1] 16 28  9 26  6 14
#> [1] 16 28  9 26  3 14
#> [1] 16 28 13 26 32 29
#> [1] 16 28 13 26 32 14
#> [1] 16 28 13 26 32  6
#> [1] 16 28 13 26 32  3
#> [1] 16 28 13 26 32 14
#> [1] 16 28 13 26 29 14
#> [1] 16 28 13 26 29  6
#> [1] 16 28 13 26 29  3
#> [1] 16 28 13 26 29 14
#> [1] 16 28 13 26 14  6
#> [1] 16 28 13 26 14  3
#> [1] 16 28 13 26 14 14
#> [1] 16 28 13 26  6  3
#> [1] 16 28 13 26  6 14
#> [1] 16 28 13 26  3 14
#> [1] 16  5  9 13 32 29
#> [1] 16  5  9 13 32 14
#> [1] 16  5  9 13 32  6
#> [1] 16  5  9 13 32  3
#> [1] 16  5  9 13 32 14
#> [1] 16  5  9 13 29 14
#> [1] 16  5  9 13 29  6
#> [1] 16  5  9 13 29  3
#> [1] 16  5  9 13 29 14
#> [1] 16  5  9 13 14  6
#> [1] 16  5  9 13 14  3
#> [1] 16  5  9 13 14 14
#> [1] 16  5  9 13  6  3
#> [1] 16  5  9 13  6 14
#> [1] 16  5  9 13  3 14
#> [1] 16  5  9 26 32 29
#> [1] 16  5  9 26 32 14
#> [1] 16  5  9 26 32  6
#> [1] 16  5  9 26 32  3
#> [1] 16  5  9 26 32 14
#> [1] 16  5  9 26 29 14
#> [1] 16  5  9 26 29  6
#> [1] 16  5  9 26 29  3
#> [1] 16  5  9 26 29 14
#> [1] 16  5  9 26 14  6
#> [1] 16  5  9 26 14  3
#> [1] 16  5  9 26 14 14
#> [1] 16  5  9 26  6  3
#> [1] 16  5  9 26  6 14
#> [1] 16  5  9 26  3 14
#> [1] 16  5 13 26 32 29
#> [1] 16  5 13 26 32 14
#> [1] 16  5 13 26 32  6
#> [1] 16  5 13 26 32  3
#> [1] 16  5 13 26 32 14
#> [1] 16  5 13 26 29 14
#> [1] 16  5 13 26 29  6
#> [1] 16  5 13 26 29  3
#> [1] 16  5 13 26 29 14
#> [1] 16  5 13 26 14  6
#> [1] 16  5 13 26 14  3
#> [1] 16  5 13 26 14 14
#> [1] 16  5 13 26  6  3
#> [1] 16  5 13 26  6 14
#> [1] 16  5 13 26  3 14
#> [1] 16  9 13 26 32 29
#> [1] 16  9 13 26 32 14
#> [1] 16  9 13 26 32  6
#> [1] 16  9 13 26 32  3
#> [1] 16  9 13 26 32 14
#> [1] 16  9 13 26 29 14
#> [1] 16  9 13 26 29  6
#> [1] 16  9 13 26 29  3
#> [1] 16  9 13 26 29 14
#> [1] 16  9 13 26 14  6
#> [1] 16  9 13 26 14  3
#> [1] 16  9 13 26 14 14
#> [1] 16  9 13 26  6  3
#> [1] 16  9 13 26  6 14
#> [1] 16  9 13 26  3 14
#> [1] 28  5  9 13 32 29
#> [1] 28  5  9 13 32 14
#> [1] 28  5  9 13 32  6
#> [1] 28  5  9 13 32  3
#> [1] 28  5  9 13 32 14
#> [1] 28  5  9 13 29 14
#> [1] 28  5  9 13 29  6
#> [1] 28  5  9 13 29  3
#> [1] 28  5  9 13 29 14
#> [1] 28  5  9 13 14  6
#> [1] 28  5  9 13 14  3
#> [1] 28  5  9 13 14 14
#> [1] 28  5  9 13  6  3
#> [1] 28  5  9 13  6 14
#> [1] 28  5  9 13  3 14
#> [1] 28  5  9 26 32 29
#> [1] 28  5  9 26 32 14
#> [1] 28  5  9 26 32  6
#> [1] 28  5  9 26 32  3
#> [1] 28  5  9 26 32 14
#> [1] 28  5  9 26 29 14
#> [1] 28  5  9 26 29  6
#> [1] 28  5  9 26 29  3
#> [1] 28  5  9 26 29 14
#> [1] 28  5  9 26 14  6
#> [1] 28  5  9 26 14  3
#> [1] 28  5  9 26 14 14
#> [1] 28  5  9 26  6  3
#> [1] 28  5  9 26  6 14
#> [1] 28  5  9 26  3 14
#> [1] 28  5 13 26 32 29
#> [1] 28  5 13 26 32 14
#> [1] 28  5 13 26 32  6
#> [1] 28  5 13 26 32  3
#> [1] 28  5 13 26 32 14
#> [1] 28  5 13 26 29 14
#> [1] 28  5 13 26 29  6
#> [1] 28  5 13 26 29  3
#> [1] 28  5 13 26 29 14
#> [1] 28  5 13 26 14  6
#> [1] 28  5 13 26 14  3
#> [1] 28  5 13 26 14 14
#> [1] 28  5 13 26  6  3
#> [1] 28  5 13 26  6 14
#> [1] 28  5 13 26  3 14
#> [1] 28  9 13 26 32 29
#> [1] 28  9 13 26 32 14
#> [1] 28  9 13 26 32  6
#> [1] 28  9 13 26 32  3
#> [1] 28  9 13 26 32 14
#> [1] 28  9 13 26 29 14
#> [1] 28  9 13 26 29  6
#> [1] 28  9 13 26 29  3
#> [1] 28  9 13 26 29 14
#> [1] 28  9 13 26 14  6
#> [1] 28  9 13 26 14  3
#> [1] 28  9 13 26 14 14
#> [1] 28  9 13 26  6  3
#> [1] 28  9 13 26  6 14
#> [1] 28  9 13 26  3 14
#> [1]  5  9 13 26 32 29
#> [1]  5  9 13 26 32 14
#> [1]  5  9 13 26 32  6
#> [1]  5  9 13 26 32  3
#> [1]  5  9 13 26 32 14
#> [1]  5  9 13 26 29 14
#> [1]  5  9 13 26 29  6
#> [1]  5  9 13 26 29  3
#> [1]  5  9 13 26 29 14
#> [1]  5  9 13 26 14  6
#> [1]  5  9 13 26 14  3
#> [1]  5  9 13 26 14 14
#> [1]  5  9 13 26  6  3
#> [1]  5  9 13 26  6 14
#> [1]  5  9 13 26  3 14

Created on 2021-10-11 by the reprex package (v2.0.1)

  • Related