{"categories":["Ruby","\u6570\u5b66"],"author_name":"obelisk2","provider_url":"https://hatena.blog","author_url":"https://blog.hatena.ne.jp/obelisk2/","published":"2022-06-01 13:07:10","blog_title":"Camera Obscura","description":"prime \u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046\u3002\u7d50\u679c\u306f\u9806\u4e0d\u540c\u3002 require \"prime\" def divisors(n) result = [1] doit = ->(pd, acc) { return if pd.empty? x, *xs = pd (0..x[1]).each do |i| e = acc * x[0] ** i result << e doit.(xs, e) end } doit.(n.prime_division, 1) result.uniq end p divisors(24) #=>[1, 3, 2, 6, 4, 12, 8, 24]","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fobelisk.hatenablog.com%2Fentry%2F2022%2F06%2F01%2F130710\" title=\"\u7d04\u6570\u3092\u6c42\u3081\u308b\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>","type":"rich","image_url":null,"url":"https://obelisk.hatenablog.com/entry/2022/06/01/130710","height":"190","version":"1.0","blog_url":"https://obelisk.hatenablog.com/","width":"100%","provider_name":"Hatena Blog","title":"\u7d04\u6570\u3092\u6c42\u3081\u308b\uff08Ruby\uff09"}