Skip to content

Instantly share code, notes, and snippets.

@kenmazaika
Created February 18, 2016 23:52
Show Gist options
  • Save kenmazaika/0e5fde0b014fb1fa367f to your computer and use it in GitHub Desktop.
Save kenmazaika/0e5fde0b014fb1fa367f to your computer and use it in GitHub Desktop.
# generate all of the touples such that
# the first value and the second value summed
# is less than or equal to the value presented
def touples(n)
touple_values = []
n.times do |x|
n.times do |y|
touple_values.push([x, y])
end
end
filtered_array = []
touple_values.each do |touple|
# touple = [1, 1]
x, y = touple
if x + y <= n
filtered_array.push([x, y])
filtered_array.push([-x, y])
filtered_array.push([x, -y])
filtered_array.push([-x, -y])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment