Skip to content

Instantly share code, notes, and snippets.

@yhirano55
Last active February 17, 2018 03:20
Show Gist options
  • Save yhirano55/8aa6d71f7343b1806763997ecbeef791 to your computer and use it in GitHub Desktop.
Save yhirano55/8aa6d71f7343b1806763997ecbeef791 to your computer and use it in GitHub Desktop.
Calculate robots sample
def calculate(n)
[1, 2, 3].repeated_combination(n).to_a.each_with_object({}) { |a, cache|
Array.new(n) do |i|
combination = a[0..i]
if combination.sum == n && !cache.key?(combination)
cache[combination] = true
end
end
}.keys
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment