Skip to content

Instantly share code, notes, and snippets.

@kimihito
Created June 13, 2012 15:30
Show Gist options
  • Save kimihito/2924772 to your computer and use it in GitHub Desktop.
Save kimihito/2924772 to your computer and use it in GitHub Desktop.
たのしいRuby10章
#-*- coding: utf-8 -*-
def cels2fahr(cels)
fahr = cels * 9 / 5 + 32
p fahr
end
cels2fahr(10) #=> 50
cels2fahr(20) #=> 68
#!/usr/bin/env ruby
#-*- coding: utf-8 -*-
def dice()
p rand(6)
end
dice()
#!/usr/bin/env ruby
#-*- coding: utf-8 -*-
def dice
rand(6)
end
def dice10
sum = 0
10.times do
sum += rand(6)
end
sum
end
p dice10
#!/usr/bin/env ruby
#-*- coding: utf-8 -*-
def fahr2cels(fa)
cels =(5.0 / 9.0) * (fa - 32.0)
end
i = 1
while i <= 100 do
print"華氏#{i}度:"
print"摂氏#{fahr2cels(i)}\n"
i += 1
end
#!/usr/bin/env ruby
#-*- coding: utf-8 -*-
def div(n)
(1..n).select{|x| n % x == 0}
end
def prime?(n)
div(n) == [1,n]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment