Created
          May 27, 2011 11:16 
        
      - 
      
 - 
        
Save tokland/995056 to your computer and use it in GitHub Desktop.  
    Problem 11 El Pais
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/ruby-1.9 | |
| require 'set' | |
| class Problem11 | |
| def self.solve(boxes, nails_per_box, weights) | |
| (1..nails_per_box).to_a.repeated_combination(boxes).select do |combination| | |
| weights.repeated_permutation(boxes).map do |weights| | |
| weights.zip(combination).map do |weight, value| | |
| weight * value | |
| end.inject(:+) | |
| end.to_set.size == 2**boxes | |
| end.map(&:to_set) | |
| end | |
| end | |
| p Problem11.solve(5, 13, [5, 6]) | |
| #=> [#<Set: {3, 6, 11, 12, 13}>, #<Set: {6, 9, 11, 12, 13}>] | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment