Skip to content

Instantly share code, notes, and snippets.

@tokland
Created May 27, 2011 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokland/995056 to your computer and use it in GitHub Desktop.
Save tokland/995056 to your computer and use it in GitHub Desktop.
Problem 11 El Pais
#!/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