LoginSignup
2
0

More than 5 years have passed since last update.

10分コーディング(github連携テスト)

Last updated at Posted at 2012-10-29
// http://ameblo.jp/programming/entry-10001721422.html

def deal = { i, str ->
  def list = []
  i.times {
    list << ""
  }
  if (str.size() < i) {
    str = ""
  } else {
    str = str[0..(str.size()-(1 + str.size() % i))]
  }
  str.eachWithIndex { s, j ->
    list[j % i] += s
  }
  list
}

assert deal(3,"123123123") == ["111","222","333"]
assert deal(4,"123123123") == ["12","23","31","12"]
assert deal(6,"012345012345012345") == ["000", "111", "222", "333", "444", "555"]
assert deal(6,"01234") == ["", "", "", "", "", ""]
2
0
1

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
2
0