Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create a Ruby class named "DistinctArray". A DistinctArray is very similar to an Array except for two differences:
- 1) it does not contain duplicate elements
- 2) it has a method named "to_multiset" which accepts one argument.
- The to_multiset method accepts an argument n. The return value should be an array of many distinct n-length arrays. Each n-length array should contain any number of copies of elements from the parent DistinctArray object.
- Example:
- distinct_array = DistinctArray.new
- 3.times {|i| distinct_array.push(i) }
- distinct_array.to_multiset(2) # => [[0,0], [1,2], [1,1], [0,2], [0,1], [2,2]]
Add Comment
Please, Sign In to add comment