#!/usr/bin/ruby # ## https://rosettacode.org/wiki/Faulhaber%27s_formula # func faulhaber_s_formula(p) { "1/#{p + 1} * (" + gather { { |j| take "#{binomial(p+1, j) * j.bernfrac -> as_rat}*n^#{p+1 - j}" } << 0..p }.join(' + ') + ")" } { |p| printf("%2d: %s\n", p, faulhaber_s_formula(p)) } << ^10