Skip to content

Instantly share code, notes, and snippets.

@mumriks mumriks/23fig.rb
Created Feb 3, 2016

Embed
What would you like to do?
平方数を除く 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
You can’t perform that action at this time.