Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Coding puzzle 2
Message
From
05/06/2002 04:45:42
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
04/06/2002 21:57:30
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00664570
Message ID:
00664848
Views:
30
Hi Hilmar

All of your versions fail to meet the specification that the function accept 2 parameters, the birthdate and the "current" date ;). I deliberately went for the shortest version that met the speck. BTW, speck with a K is what I call anything that should have been a specification, but wasn't <g>.

>>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!
>
>Meneer Peter,
>
>I came up with three different versions of the age function.
>
>Version 1 is the fastest.
>
>Version 2 is slower to execute, but execution speed wasn't specified as a criterion.
>
>Version 3 is the shortest of them all, but won't work for people more than ca. 100 years old. It is only good for "showing off". However, I think it is correct for younger people.
>
>
>* Version 1
>function age(d)
>y=year(date())-year(d)
>retu y-iif(gomo(d,y*12)<date(),0,1)
>
>* Version 2
>function age(d)
>y=0
>do whil d<date()
>	d=gomo(d,12)
>	y=y+1
>endd
>retu y-1
>
>* Version 3
>function age(d)
>retu iif(gomo(d,12)>=date(),0,age(gomo(d,12))+1)
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform