LoginSignup
0
0

More than 1 year has passed since last update.

Railsで効率的に列を捌ける仕組みを考える

Last updated at Posted at 2022-11-27

ルール

作業可能レーンに順番にかかる作業時間がバラバラなタスクが流れてきて、最終的に作業可能レーンにタスクがなくなる時間を知りたい

具体的に

timesには、作業にかかる時間が適当な数定義されており、
tillは作業可能レーン数が定義されている。
最終的に全部のtillsで作業が終わる時間が知りたい。

times = [3,4,5,6,7,8,9,20,30]
till = 5
tills = Array.new(till, 0)
# => tills
# => [0, 0, 0, 0, 0]

求め方

timesをeachでまわし、tillsの中で一番作業時間が少ないをindex()の引数に持ち、
その列をtillsから特定して、eachの値を加算していく.

times.each {|time| tills[tills.index(tills.min)] += time}

tills.max
#> tills
#=> [11, 13, 25, 36, 7]
#> tills.max
#=> 36
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0