-2

Is there a simple way of finding all the combinations of 6 digits using only 0, 1 and 2?

So it starts like 000000 and finishes 222222

I have looked online but all i can find is the formula for finding how many there are but i need a list of all of them

If there is a code in R that will be even better

It is not completely neccessary but if there is a way to create a list where the 1st and 4th digit sum to a maximum of 2, 2nd and 5th digit sum to a maximum of 2 and 3rd and 6th digit sum to a maximum of 2

Thankyou

Summer Gleek
  • 334
  • 5
  • 15

1 Answers1

4

You can do:

do.call(paste0, expand.grid(rep(list(0:2), 6)))

Adding a rev in there gives a different order that might feel more natural:

do.call(paste0, rev(expand.grid(rep(list(0:2), 6))))

I will only give you a hint for your new (added) question as I am now worried I might be doing your homework. expand.grid returns a data.frame. With a little work on it, you can probably extract the subset of rows that only matter to you.

flodel
  • 87,577
  • 21
  • 185
  • 223