Prev: (Sorry for the non french speaking peoples) Un logiciel de géométrie dynamique pour HP
Next: Dust inside 50g. How to clean? How to prevent?
From: stephen on 27 Mar 2010 13:13 Thank you very much, Dave and Han, for the encouragement and advice! I've got it down to about 7.5 minutes now. I created this little program to help me to time it: Just put the name of the program on the stack and run this one: TimIt: << TIME -> X << EVAL TIME HMS-> X HMS-> - 3600 * "dt(s)" ->TAG >> >> Thanks, Stephen
From: TW on 27 Mar 2010 14:58 > TimIt: > << TIME -> X << EVAL TIME HMS-> X HMS-> - 3600 * "dt(s)" ->TAG >> >> Good. Now look at the command TEVAL. Input is an item to evaluate. . . :-) TW
From: stephen on 27 Mar 2010 15:24 On 27 Mar, 18:58, TW <timwess...(a)gmail.com> wrote: > > TimIt: > > << TIME -> X << EVAL TIME HMS-> X HMS-> - 3600 * "dt(s)" ->TAG >> >> > > Good. Now look at the command TEVAL. Input is an item to > evaluate. . . :-) > > TW Oh great! I'm going to assign a user key for that one! :) Thanks, Stephen
From: Dave Hayden on 28 Mar 2010 11:27 Here's my solution. TEVAL on my 50g says it takes 26.3 seconds. This program skips candidates ending in odd digits. It further restricts he candidates by considering only those ranges of X that can result in X^4 beginning with a digit between 5 and 9. « 1 1. 0. N OK ANSWER« @ N is the number of digits in X^4 @ OK is a temporary @ ANSWER is the final answer WHILE ANSWER NOT REPEAT @ If X^4 has N digits then @ 5x10^N < X^4 < 10^(N+1) @ Also, it can be shown that numbers ending @ in an odd digit always result in a small @ value for the least significant digit (or @ the second digit when last digit=5). Numbers @ ending in zero are also bad. @ Compute low bound for X 5. LOG N + 4. / ALOG CEIL IF DUP 2. MOD THEN 1. + END @ Compute high bound for X N 1. + 4. / ALOG FLOOR IF DUP 2. MOD THEN 1. - END FOR X X 1. DISP X RI 4 ^ STR 1. 'OK' STO WHILE DUP SIZE OK AND REPEAT DUP HEAD "4" > 'OK' STO TAIL END DROP IF OK THEN X 'ANSWER' STO 1.E499 'X' STO @ stop the loop END 2. STEP @ even numbers only 1. 'N' STO+ END ANSWER » »
From: Dave Hayden on 28 Mar 2010 20:48
Here is a solution in HPGCC. On the 50g with TEVAL it takes 0.076 seconds. Note that the original post specified User RPL, so this only qualifies as an "interesting cheat." :) Interestingly, calling sys_slowOff()/sys_slowOn() made no difference. I suspect that most of the runtime is spent just loading the program. Dave --------------------- #include <hpgcc49.h> #include "hpobjects.h" int main (int argc, char **argv) { unsigned rpl_stack_bias = sat_stack_init(); int N; long long X=0; long long X4; /* X^4 */ int answer = 0; for (N=1; answer == 0; ++N) { int low, high; low = ceil(pow((log10(5) + N) / 4, 10)); if (low % 2) ++low; high = floor(pow( (N+1)/4.0, 10)); if (high % 2) --high; for (X=low; X <= high; X += 2) { char buf[50]; int i; int len; int ok = 1; X4 = X*X*X*X; sprintf(buf, "%L", X4); len = strlen(buf); for (i=1; ok && i < len; ++i) { if (buf[i] < '5') ok = 0; } if (ok) { // You found it!! answer = X; break; } } } STACKpush(REALencode((double)X, 0)); sat_stack_exit(rpl_stack_bias); return 0; } |