Created
February 18, 2016 23:52
-
-
Save kenmazaika/0e5fde0b014fb1fa367f to your computer and use it in GitHub Desktop.
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
| # 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