Created
February 3, 2016 04:23
-
-
Save mumriks/89535ae95f52f7a42518 to your computer and use it in GitHub Desktop.
平方数を除く 2,3,5,6,7,8,10... という数列で、指定番目の数を返す関数
This file contains 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 fig2(num) | |
count = 0 | |
i = 2 | |
until count == num | |
count += 1 if Math.sqrt(i) != Math.sqrt(i).to_i | |
i += 1 | |
end | |
return i - 1 | |
end | |
def fig3(num) | |
i = 2 | |
j = 1 | |
until num <= i * j | |
i += 1 | |
j += 1 | |
end | |
return num + j | |
end | |
def fig4(num) | |
num + Math.sqrt(num + Math.sqrt(num).to_i).to_i | |
end | |
def fig5(num) | |
1 + num + Math.sqrt(num - Math.sqrt(num).to_i).to_i | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment