Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Coding puzzle 2
Message
From
05/06/2002 19:20:56
 
 
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00664570
Message ID:
00665208
Views:
14
>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!

Ok folks! Here are the votes from the jury. But first let me say that I've decided to ignore the lpar statement. So, the length is the part after that statement. A carriage return is counted as one char.

Gibson:
49 characters
Nice score.
lpar b,d
RETU floo(INT((VAL(DTOS(d))-VAL(DTOS(b))))/10000)
Valenca:
48 characters
Not bad, and probably faster than the 44 char routine from Zonneveld. (But speed wasn't a criterium, I know.)
lpar B,D
A=year(D)-year(B)
RETU iif(gomo(B,A*12)>D,A-1,A)
Zonneveld:
44 characters
I like this one. It's a beautiful recursive function. However, it's not really robust, especcially in the (near?) future when we finally know the secret of youth. Also, I had to improve the routine, because the original stated >= where it should be > only. Unless of course people in South America still have their old age on their birthday.
ONE POINT!
lpar b,d
retu iif(gomo(b,12)>d,0,age(gomo(b,12),d)+1)
Santerre:
43 characters
Nice improvement of Booth's algorithm.
lpar b,d
RETU INT((VAL(DTOS(d))-VAL(DTOS(b)))/10000)
Zonneveld:
39 characters
Superb improvement.
THREE POINTS!!! THE WINNER!
lpar b,d
RETU INT(eval(dtos(d)+"-"+dtos(b))/1e4)
Nosonovsky:
8 characters
ONE POINT, for it does show lateral thinking!
lpar b,d
RETU d-b
Nadia, Hilmar and Hilmar, congratulations! Oops, I can't give four points to Hilmar, so I'll give that one point to Santerre, who obviously inspired Hilmar.

And many thanks to all other contestants! You were great! Hope I didn't make incorrect conclusions. If that's the case, sorry.

SH.T. I can't give points in the chatter area! Sorry folks, all effort for nothing. Michel, it's time to start a vfp-puzzle area!

Next puzzle please... :)
Groet,
Peter de Valença

Constructive frustration is the breeding ground of genius.
If there’s no willingness to moderate for the sake of good debate, then I have no willingness to debate at all.
Let's develop superb standards that will end the holy wars.
"There are three types of people: Alphas and Betas", said the beta decisively.
If you find this message rude or offensive or stupid, please take a step away from the keyboard and try to think calmly about an eventual a possible alternative explanation of my message.
Previous
Reply
Map
View

Click here to load this message in the networking platform