Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Coding puzzle 2
Message
De
05/06/2002 10:23:14
Mike Yearwood
Toronto, Ontario, Canada
 
 
À
05/06/2002 10:13:55
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
00664570
Message ID:
00664926
Vues:
26
That's clever!

>>>>Ok, that 'puzzle' from Hilmar was far too easy (took me 10 seconds, ok .. 30).
>>>>
>>>>Here's a nice contest. Who can write the shortest function (using native vfp functions/commands) that returns a person's age. Input is the birthday and the current date. The winner will get 3 points from me!
>>>
>>>59 Gibson:
lpar b,d
>>>RETU floo(INT((VAL(DTOS(d))-VAL(DTOS(b))))/10000)
>>>
>>
>>BTW, this one was not really from Gibson, this is the Jim Booth's solution :-)
>>
>>Optimized to save characters:
>>
>>I have look at it and notice that the INT() part was not needed at all.
>>I have used the INT() function instead of FLOOR() to save one more char.
>>Using the "FUNCTION age(b,d)" declaration, no need of "lPar B,d"
>>
>>RETU INT((VAL(DTOS(d))-VAL(DTOS(b)))/10000)
>>
>>
>>The shortest function was now at 43 chars :-)
>
>This can be further shortened, replacing the two val() with an eval(), and using scientific notation for "10000":
>
>
>RETU INT(eval(dtos(d)+"-"+dtos(b))/1e4))
>
>
>(39 characters)
>
>Hilmar.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform