Skip to content

Instantly share code, notes, and snippets.

@mumriks
Created February 3, 2016 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mumriks/89535ae95f52f7a42518 to your computer and use it in GitHub Desktop.
Save mumriks/89535ae95f52f7a42518 to your computer and use it in GitHub Desktop.
平方数を除く 2,3,5,6,7,8,10... という数列で、指定番目の数を返す関数
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