martes, 23 de octubre de 2012

Understanding Programming


Oct 22

We were supposed to present our project Euler program. Of course, my group wasn't entirely done with the problem, since we don't really know how to solve it. Pablitos group went first and actually took the whole class to solve it since it wasn't entirely done. I paid attention the whole class and actually understood a lot of things, like the meaning of a string and of a substring, and actually got some ideas on how to solve my problem.

This is how Pablito´s program ended up:
d = 100
f = 1
n = 2
begin
  f = f * n
  n = n + 1
end while  ( n < = d)
f_s = f.to_s      -----à here he is passing the answer to a string
sum = 0
0.upto f_s-length do |i|
sum = sum + f_s [i].to_i         -----à here he is passing the string back to a number
end
print sum


No hay comentarios:

Publicar un comentario