def max(x,y) if y < x x else y end end
def sign(x) if x < 0 -1 else if 0 < x 1 # not(x < 0) and 0 < x else 0 # not(x < 0) and not (0 < x) end end end
def is_even(x) x%2 == 0 end
def tnpo(n) if is_even(n) n/2 else 3*n + 1 end end
irb(main):001:0> tnpo(tnpo(tnpo(7)))
s="abra" t="cadabra" u=s+t "123"+"456" s.length() (s+t).length() s[0..0] s[1..2] t[1..(t.length()-1)]
irb(main):001:0> s="abra" => "abra" irb(main):002:0> t = "cadabra" => "cadabra" irb(main):003:0> t[1..3]+s[1..2]
load("./make1d.rb") make1d(10) load("./make2d.rb") make2d(4,2)
def squares (n) a=make1d(n) for i in 0..(n-1) a[i] = i * i end a end
load("./make1d.rb") squares(10)
def german() image = make2d(3, 5) for x in (0..4) image[0][x]=[0,0,0] # black image[1][x]=[1,0,0] # red image[2][x]=[1,1,0] # yellow end image end
load("./make2d.rb") show(german())
load("./make2d.rb") def sphere(s) image = make2d(s,s) for y in 0..(s-1) for x in 0..(s-1) image[y][x] = b(s,x,y) end end image end
# 教科書 P.10 練習1.2(a)のdistance def distance(x,y,u,v) # ここにdistanceの定義を書く end def b(s,x,y) # ここにbの定義を書く end