Hatena::Grouprubyist

trotrの日記

 | 

2008-01-20

こんな風に生活してみたい* 14:12

=begin
  n -- 自分のこなせる仕事量
  a -- これからのスケジュール
=end

def divide n
  x = n / 2
  (2*x == n)? [x,x] : [x, x+1]
end

def divide_task(task, n)
  task.map{ |e| (e <= n)? e : divide_task(divide(e), n)}
end

def run(a, n)
  puts a.join(" => ")
  xs = divide_task(a, n)
  puts xs.map{ |e| layout(e)}.join(" => ")
end

def layout(e)
  e.respond_to?(:flatten)? e.flatten.join(",") : e
end

a = (1..10).to_a
run(a, 3) 
# >> 1 => 2 => 3 => 4 => 5 => 6 => 7 => 8 => 9 => 10
# >> 1 => 2 => 3 => 2,2 => 2,3 => 3,3 => 3,2,2 => 2,2,2,2 => 2,2,2,3 => 2,3,2,3

 |