Skip to content

Instantly share code, notes, and snippets.

@Rojo
Forked from edymerchk/suma_cubos.rb
Last active June 6, 2018 03:48
Show Gist options
  • Save Rojo/2a7518664d3b56e99239 to your computer and use it in GitHub Desktop.
Save Rojo/2a7518664d3b56e99239 to your computer and use it in GitHub Desktop.
Para los números del 0 al 999, realizar la suma de los cubos de los digitos que los componen.
# abc=a^3+b^3+c^3
i = 0
max = 999
while i <=999
puts i.to_s.rjust(3,'0') if i == ((i /100) ** 3) + ((i % 100 / 10) ** 3) + ((i % 10) ** 3)
i +=1
end
=>
000
001
153
370
371
407
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment