// 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") == ["", "", "", "", "", ""]
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
20