Post Reply 
Programming Exercise (HP-15C, 15C LE - and others)
04-02-2014, 04:25 PM
Post: #81
RE: Programming Exercise (HP-15C, 15C LE - and others)
How about the ND1 from Naive Designs, a programmable RPL+ calculator that runs on iOS (iPhone, iPod, iPad)? It runs HP48 series-like RPL code with enhancements (right now, about 500 functions), as well as JavaScript.

Note: all programs return this result in the display: 0.693097183059948; when I attempted to

Here is the code for RPL+; it runs in about 3.3 seconds on an iPod 4:

Code:
≪ 1 10000 2 FOR r r @dup IF isEven THEN inv - ELSE inv + END -1 STEP ≫

A much faster version uses a vector and splits it into two parts; it runs in about .1 second on an iPod 4 (written by the creator of ND1:

Code:
≪ 10000..1 inv unzip total swap total swap - neg ≫

And here is one version for J

Code:
function () {
var t = 1;
for (var j = 10000; j >= 2; j--) {
   if (calculator.functions.isEven(j))
      t -= 1/j;
   else {
      t += 1/j;
          }
    }
    return (t);
}

Here is a better version (no testing for even/odd, written by the creator of ND1); this runs in about .07 seconds on an iPhone 5s:

Code:
function() { /*as is*/
    var sum = 0;
    for (var n=9999; n=1; n -= 2)
        sum += 1/n - 1/(n+1);
    return sum;
}

And a third way, by the same person; runs in about ,0006 seconds on an iPhone 5s:

Code:
function() { /*as is*/
    var sum = 0;
    for (var n=9999; n=1; n -= 2)
        sum += 1/(n*(n+1));
    return sum;
}

Check out ND1 on the Apple App Store (or ND0 for a limited trial version); the website is http://www.naivedesign.com/ND1/ND1.html

David Motto
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming Exercise (HP-15C, 15C LE - and others) - DGM - 04-02-2014 04:25 PM



User(s) browsing this thread: 1 Guest(s)