{"categories":["Ruby"],"url":"https://obelisk.hatenablog.com/entry/2018/10/09/162738","description":"def divide(x, n) result = [] return [] if n.zero? return [[0] * n] if x.zero? return [[x]] if n == 1 0.upto(x) do |i| result += divide(x - i, n - 1).map {|a| a + [i]} end result end p divide(5, 3) \u7d50\u679c\u30025 \u3092 3\u3064\u306b\u5206\u5272\u3057\u3066\u3044\u308b\u3002 [[5, 0, 0], [4, 1, 0], [3, 2, 0], [2, 3, 0], [1, 4, 0], [0, 5, 0], [4, 0, 1], [3, 1, \u2026","height":"190","published":"2018-10-09 16:27:38","type":"rich","provider_name":"Hatena Blog","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fobelisk.hatenablog.com%2Fentry%2F2018%2F10%2F09%2F162738\" title=\"\u81ea\u7136\u6570\u3092 n \u500b\u306b\u5206\u5272\u3059\u308b &amp; \u91cd\u8907\u7d44\u307f\u5408\u308f\u305b\uff08Ruby\uff09 - Camera Obscura\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","image_url":null,"blog_url":"https://obelisk.hatenablog.com/","provider_url":"https://hatena.blog","author_url":"https://blog.hatena.ne.jp/obelisk2/","title":"\u81ea\u7136\u6570\u3092 n \u500b\u306b\u5206\u5272\u3059\u308b & \u91cd\u8907\u7d44\u307f\u5408\u308f\u305b\uff08Ruby\uff09","author_name":"obelisk2","blog_title":"Camera Obscura","version":"1.0","width":"100%"}