{"url":"https://blog.tmtms.net/entry/2016/07/27/ruby-split-array","provider_url":"https://hatena.blog","published":"2016-07-27 19:22:14","width":"100%","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fblog.tmtms.net%2Fentry%2F2016%2F07%2F27%2Fruby-split-array\" title=\"\u8981\u7d20\u6570\u304c\u3067\u304d\u308b\u3060\u3051\u5747\u7b49\u306b\u306a\u308b\u3088\u3046\u306b\u914d\u5217\u3092\u5206\u5272\u3059\u308b - tmtms \u306e\u30e1\u30e2\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","title":"\u8981\u7d20\u6570\u304c\u3067\u304d\u308b\u3060\u3051\u5747\u7b49\u306b\u306a\u308b\u3088\u3046\u306b\u914d\u5217\u3092\u5206\u5272\u3059\u308b","image_url":"https://cdn-ak.f.st-hatena.com/images/fotolife/t/tmtms/20160728/20160728215136.png","type":"rich","author_url":"https://blog.hatena.ne.jp/tmtms/","categories":["Ruby"],"blog_title":"tmtms \u306e\u30e1\u30e2","height":"190","author_name":"tmtms","version":"1.0","blog_url":"https://blog.tmtms.net/","description":"\u4f8b\u3048\u307010\u500b\u306e\u8981\u7d20\u3092\u6301\u3064\u914d\u5217\u304c\u3042\u3063\u3066\u3001\u3053\u308c\u30923\u3064\u306b\u5206\u5272\u3057\u305f\u3044\u6642\u306b\u3001 a = [1,2,3,4,5,6,7,8,9,10] n = 3 m = Rational(a.size, n).ceil a.each_slice(m).to_a #=> [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]] \u307f\u305f\u3044\u306b\u3059\u308b\u3068\u30013\u3064\u306b\u306f\u5206\u5272\u3067\u304d\u308b\u3093\u3067\u3059\u304c\u3001\u8981\u7d20\u6570\u304c 4, 4, 2 \u3068\u504f\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u3053\u308c\u3092\u4f8b\u3048\u3070 4, 3, 3 \u306e\u3088\u3046\u306b\u3057\u305f\u3044\u3002 a = [1,2,3,4,5,6,7,8,9,10] n = 3 n.times.map{|i| a[a.size*i/n ... a.size\u2026","provider_name":"Hatena Blog"}