Guest User

Untitled

a guest
Jul 17th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. Create a Ruby class named "DistinctArray". A DistinctArray is very similar to an Array except for two differences:
  2. 1) it does not contain duplicate elements
  3. 2) it has a method named "to_multiset" which accepts one argument.
  4. 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.
  5.  
  6. Example:
  7. distinct_array = DistinctArray.new
  8. 3.times {|i| distinct_array.push(i) }
  9. 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