Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina


I spent a few hours to­day round Code Golf and here's a neat thing I did.I think this is python's short­est pos­si­ble fac­to­ri­al:

f=lambda x:x<2or x*f(x-1)

You may say it's not cor­rec­t, be­cause f(1) re­turns True, but in­t(True) is 1, so it's al­most there ;-)

And here's a sur­pris­ing­ly read­able (as long as you know pas­cal's tri­an­gle) and not too long an­swer to their choose chal­lenge:

while c<k:a*=n-c;c+=1;a/=c
print a

Contents © 2000-2020 Roberto Alsina