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
| def pentagon | |
| pentagon = [] | |
| i = 1 | |
| loop do | |
| pentagon << i * (3 * i - 1) / 2 | |
| pentagon.each_with_index do |item, index| | |
| for b in index+1..pentagon.size-1 | |
| puts "P1 #{pentagon[index]} P2 #{pentagon[b]}" if in_penta?(pentagon[index] + pentagon[b]) && in_penta?(pentagon[b] - pentagon[index]) | |
| end |
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
| class Pentagon | |
| def initialize(i) | |
| (i * (3 * i - 1) / 2) | |
| end | |
| end | |
| pe = Pentagon.new(10) |
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
| class Pentagon | |
| def initialize(i) | |
| puts (i * (3 * i - 1) / 2) | |
| end | |
| end | |
| pe = Pentagon.new(10) |
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
| class Pentagon | |
| def initialize(element) | |
| penta = [] | |
| for i in 1..element | |
| penta << (i * (3 * i - 1) / 2) | |
| i += 1 | |
| end | |
| puts penta |
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
| class Pentagon | |
| def initialize(element) | |
| penta = [] | |
| for i in 1..element | |
| penta << (i * (3 * i - 1) / 2) | |
| i += 1 | |
| end | |
| puts penta |
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
| class Pentagon | |
| def initialize(element) | |
| penta = [] | |
| for i in 1..element | |
| penta << (i * (3 * i - 1) / 2) | |
| i += 1 | |
| end | |
| puts penta |
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
| class Coincidence | |
| def find | |
| results = {} | |
| i = 1 | |
| loop do | |
| triangle = i*(i+1)/2 | |
| pentagonal = i*(3*i-1)/2 | |
| hexagonal = i*(2*i-1) |
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
| class Coincidence | |
| @results = {} | |
| @i = 1 | |
| def self.find | |
| loop do | |
| triangle = @i*(@i+1)/2 | |
| pentagonal = @i*(3*@i-1)/2 | |
| hexagonal = @i*(2*@i-1) |
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
| def self.continue? | |
| user_input = "" | |
| until user_input == ("y" || "n") do | |
| puts "Do you want to continue search? y/n" | |
| user_input = gets.chomp.downcase | |
| end | |
| user_input == "y" ? nil : break | |
| end |
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
| module TestModuleExtend | |
| @@var_class = 55 | |
| @var_class = 45 | |
| def var_class | |
| @@var_class | |
| end | |
| def var_class_instance | |
| @var_class |