Factorial amb Ruby

02 de Noviembre de 2007, editado por Josep Sirvent

M’acabo d’enterar que per calcular el factorial d’un número amb un ordinador t’has de buscar la vida. Una operació que una calculadora CASIO fa sense miraments, un potent llenguatge de programació no ho porta integrat. Hom creu que el factorial és un concepte suficientment necessari com per no haver de calcular-se’l “manualment”. Com no podira ser d’una altra manera, vaig deixar d’estudiar probabilitat una estona per resoldre aquest “pique” personal amb la informàtica de consum:

Factorial d’un nombre amb Ruby:

def factorial(x)
if x == 0
return 1
else
resultat = x
while x > 1
resultat = resultat*(x-1)
x = x-1
end
return resultat
end
end


Noticias similares
Deja tu comentario

7 comentarios a esta noticia

  1. Jordi Carrasco comenta:

    El divendres un amic meu al sopar em deia que el Ruby estava mort. Instintivament jo vaig negar-me (sense fundaments pq no hi entenc) però portat per la ira totalment xd

    El cas és que diu que php5 li dona mil voltes al Ruby.

  2. abercrombie fitch uk comenta:

    Well, it should be…

    Yep what.s good for the goose is good for the gander. Great idea.

  3. ed hardy clothing comenta:

    amplify blogshttp albeit markets doable illness unironically studying gkthiqj ponds employer

  4. abercrombie and fitch comenta:

    I really thank to one who wrote this article. I have always been reading and writing texts like this in blogs. Also, I, as a daily writer, present my respects to everyone. I just watched videos like this in research in all areas.
    I think people must first research before writing.

  5. tiffany outlet comenta:

    Specialists argue that home loans aid people to live the way they want, just because they can feel free to buy necessary goods.how to do a stimulus package here in the US

  6. abercrombie comenta:

    they can feel free to buy necessary goods.

  7. hollister clothing comenta:

    cialis bestellen epia bcberweisung cialis 10 mg neupreis cialis generika rezeptfrei

Deja tu comentario