|My birthday, so a little commemorative mini-challenge !|
Message #1 Posted by Valentin Albillo on 5 Mar 2013, 7:34 a.m.
As fate would have it, today's my birthday (don't ask) so I think that a little commemorative mini-challenge is in order, namely:
The commemorative mini-challenge
Write a short program or code snippet to evaluate a given polynomial at any given particular argument X, without explicitly using either multiplication/division operators (*, /)(that excludes reciprocals as well) or addition/subtraction operators (+, -).
For good measure, any and all kinds of conditional, looping, or Go-To statements or constructions are forbidden as well so no equivalents to IF, GOTO, SELECT, CASE, UNTIL, WHILE, LOOP, FOR, ... you get the point.
To simplify matters a little you can particularize your code to evaluate this particular 5th-degree polynomial:
y = 5 x5 + 8 x4 + 4 x3 + 2 x2 + 3 x + 1
for any given argument X (the generalization to arbitrary polynomials is obviously straightforward).
Assorted HP models can be used for this challenge (not all can deliver) but in case your particular model has a built-in (or library's) polynomial evaluation functionality (say "CALL POLYEV(coefficients, X)") you're asked not to use it lest you'll ruin the challenge for yourself.
I'll give a 3-line HP-71B solution, which runs like this:
? PI ( X value )
2463.56024568 ( P(x) )
Try your hand at it, it's actually quite easy !
Best regards from V.