How can I count special type of combinations with matlab?

Hi: I am a computer engineer and I am trying to count the following type of combinations with an unknown built-in function in Matlab: Let K={1,2,...,20} be the set of the first 20 integers.Consider all combinations of 9 elements selected from the set K.How many of these combinations contain elements that differ by 3? For example (7,10,11,12,14,17,18,19,20)has elements 7 and 10 whose difference is 3 while the combination (1,2,6,7,8,12,13,14,19) has no elements with difference 3. Using Matlab,how many combinations are there that contain elements that differ by 3? Thank you in advance.

2 Comments

This sounds a lot like homework. What have you tried so far?
Any difference or just the difference between two neighbours? Does [7 8 9 10 ....] counts because there is 10-7=3?

Sign in to comment.

Answers (1)

Anyway, darkness golf:
  • 40 characters: to return the matrix of combos without suppressing output and assigning to 'ans'
  • 36 characters: to get the number of combinations without suppressing output and assigning to 'ans'

8 Comments

If just for neighboring difference, I got 36 characters. The result is 120616. What's yours?
yes, I assumed sorted neighbors and I also have 120616. 36!! huummmphhh
Well, I didn't sort. Why do you need to sort?
Ahh, counting just the number, not actually returning the matrix, I get 36 (not setting it to a variable or terminating output)
Not sorting, just saying neighbors in a sorted list; i.e. combinations are sorted and can not be any permutation.
Which brings up the campfire question us nerds had the other night: why are "combination" locks called "combination locks" and not "permutation locks" since that's what they really are?
I think we got the same solution. "Combination lock" is just easy for average folks.
Hmmm -- some "combination locks" allow repeated numbers (especially the disc-type line-up-the-numbers locks). I'm not sure that "permutation" would be appropriate either.

Sign in to comment.

Asked:

on 25 Aug 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!