## PocketCalc

remixed by scratchkid007
Instructions

Start by pressing a green flag. You can click the buttons on screen or use the keyboard: N="±", V="√", C="C", Z="AC", P=".", T="%", M="*", A="+", Q="?", D="/", S="-", E="=", L="MC", R="MR", I="M-", U="M+", Y="MS", X="X". (Scratch-programs can only use arrow-keys, 0-9, and a-z (and doesn't know shift-key status), except in answer-boxes where all characters can be typed.)

The question-mark-button "?" enters the program editor. You use the same symbols when programming as on the buttons on-screen, except that you use "*" and "/", and you can use "n" and "v" instead of "±" and "√". The programs are case-insensitive and unknown commands are ignored.

An example program computing √10 using Newton–Raphson method is stored (AC MC 1 M+ A0 10 / MR - MR / 2 M+ JT0 MR). Press Enter or click the OK-button to run the current program or type in a new.

The labels/anchors are A0 to A9 and there are five jump-commands: JU (unconditional), JT (true), JF (false), J+ (>=0), and J- (<0), e.g. JT0 goes to anchor A0 if the display is not close to zero (i.e. |display| > 9E-16).

You can select memory by using e.g. 7 MS (short for Memory Select). The M-commands then use memory 7. The default-memory is 0 and you can use as many memories as the Scratch Player allows. I believe this indirect addressing of memory together with the conditional jump-commands makes PocketCalc Turing-complete. You can eXchange the display with a hold-memory using X (similar to Sed).

You can call a subroutine/procedure/function if you precede a jump-command with _ e.g. _JU1. You can return from a subroutine using a jump with the special anchor/label ^ e.g. JU^. If you use ^ as a command it pops the return-stack but ignores the result. Actually _ pushes the program-counter to the return-stack.

There is a pause-command p that stops execution, to resume click ? and OK-button (or press Q and Enter). While pausing you can use the calculator as you normally would.

This example computes nCr (combination), e.g. possible poker-hands (5 cards) from 52 cards: 52 q
x5_ju3_ju2x1_ju3
px6_ju3_ju2x2_ju3
5msmrx6msmrx-x=_ju2x3_ju3
x2msmr*x=x1msmr/x=x0msxju0
a2x0_ju3 1xmra1*x=x1m-mrjt1xju^
a3msxmcm+ju^a0
Enter 5 q Enter

Another example: Simpson's Rule compute the integral for y=2x^2+3x-1 in the interval 1 to 5 with 6 divisions: 6 q
x0_ju4
px1_ju4
px2_ju4x1msmr-x=x0msmrx/x=x1_ju43msmc1
a0x4_ju4_ju1x4msmr*x=x3msxm+1msmrx2msxm+0ms1m-mrjt2_ju1x3msxm+mrx1msmr*x/3=ju5
a24msmr-4=jt32ju0
a34ju0a4msxmcm+ju^
a1
2msmr*=*2=x3*mr=+x-1=
ju^a5
Enter 5 q Enter 1 q Enter
Should show 114.66667.
You can change the integrand by editing between a1 and ju^.

Notes and Credits (added by scratchkid007)

Shared: 18 Dec 2013 Modified: 18 Dec 2013

More projects by scratchkid007