Created
August 20, 2013 12:58
-
-
Save highercomve/6281013 to your computer and use it in GitHub Desktop.
Sumatoria de X^N desde X -> 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sumatoria a la N | |
def sumatoria_n(x, n) | |
(1..x).inject { |sum, i| sum += i**(n) } | |
end | |
# Derivaciones del método sumatoria_n | |
funciones = ["enteros", "cuadrados", "cubos", "cuarta"] | |
# Creación de métodos: | |
# sumatoria_enteros, sumatoria_cuadrados, etc. | |
funciones.each.with_index(1) do |method, n| | |
define_method "sumatoria_#{method}" do |x| | |
sumatoria_n(x, n) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment