Created
April 25, 2013 15:43
-
-
Save hiddenpower/5460741 to your computer and use it in GitHub Desktop.
1.- Cantidad de sumas no repetidas que forman un entero
2.- Obtencion de cubos mediante suma de impares
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
def sumas(n) | |
a = n | |
result = 0 | |
for i in 0..n | |
if i <= a | |
result += 1 | |
a -= 1 | |
end | |
end | |
result | |
end | |
sumas(5) | |
def cubo(n) | |
i=1 | |
answer = 0 | |
start = (n*n)-(n-1) | |
while i <= n | |
answer += start | |
start = start + 2 | |
i+=1 | |
end | |
answer | |
end | |
cubo(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment