Sunday, May 12, 2024

Python and Calculator Basic: Determine if a Character is in a String

 Python and Calculator Basic: Determine if a Character is in a String

Calculators: Casio fx-CG 50, TI-84 Plus CE


Today’s blog gives a technique on determining whether a character is present in a string.


Problem


We are given the string “a+b*c” and we are determine if the following characters are present in the string: “a”, “b”, “c”, “d”, and “e”.


Let str1 be the string to be searched.


Since the goal is to search single characters, construct a string that would contain all the characters. We can use this string to pick out the character to search for. For our problem, this particular string is “abcde”, which will name this string, str2.


Code: Python


This code was entered on a fx-CG 50, but it should work on all calculators and platforms with Python. No modules are needed.


Script: instring.py


str1=”a+b*c”

str2=”abcde”

l=len(str2)

t=0

print(“\ncounts a-e:”)

for i in range(l):

  s=str2[i]

  c=str1.count(s)

  t+=c

  print(s,c,t)


Notes:


\n: start a new line in a string


string.count(target string): returns the count of when the target string occurs


string[n]: calls the nth character of a string (0 to n – 1)



Basic Code: Casio fx-CG 50


“A+B×C” → Str1

“ABCDE” → Str2

StrLen(Str1) → L

StrLen(Str2) → M

0 → T

For 1 → I To M

0 → C

StrMid(Str2, I, 1) → Str4

For 1 → J To L

StrMid(Str1, J, 1) → Str3

StrCmp(Str3, Str4) = 0 ⇒ C + 1 → C

Next

T + C → T

ClrText

Locate 1, 3, Str4

Locate 1, 4, C

Locate 1, 5, T

“ “◢

Next


Notes:


The alpha variables are upper case.


StrMid(string, starting point, number of characters): extract a sub-string starting with the nth character


StrCmp(string 1, string 2): compares the character value of a string. If the values are equal, the function returns 0. This command works well with strings of one character.


A blank string with one space (“ “), followed by a display character (◢) will pause the screen.


Basic Code: TI-84 Plus CE


“A+B*C” → Str1

“ABCDE” → Str2

length(Str1) → L

length(Str2) → M

0 → T

ClrHome

For(I, 1, M)

0 → C

sub(Str2,I,1) → Str4

For(J,1,L)

sub(Str1,J,1) → Str3

If Str3 = Str4

C +1 → C

End

T + C → T

Disp Str4 + “ “ + toString(C) + “ “ + toString(T)

End


Notes:


The alpha variables are upper case.


sub(string, starting point, number of characters): extract a sub-string starting with the nth character


Strings can be compared directly.


Results


The result of all three algorithms should give:


Character

C (count)

T (accumulative total)

a

1

1

b

1

2

c

1

3

d

0

3

e

0

3


I hope this helpful,


Eddie


All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


HP 71B: Basic RPN Program

HP 71B: Basic RPN Program



Repost


This is a repost of a basic program for the HP 71B. I received an email from Kenneth who pointed out that line 145 lead to an error. In further testing, this lead to the input routine not working correctly. The following code in today’s repost is a corrected algorithm. Edited lines are in blue (lines 5, 125, and 145).


The original entry, posted on August 29, 2016, will be deactivated.


HP 71B Program: BASIC


The program RPNBASIC puts the HP 71B into RPN mode with arithmetic functions, power, square root, and π.  The program contains room for one independent memory and a four level stack that works like the classic Hewlett Packard RPN calculators. 


I have the array S set up for six slots:

Slot 1: X stack (display)

Slot 2: Y stack

Slot 3: Z stack

Slot 4: T stack

Slot 5: Independent memory stack

Slot 6: (temporary memory)


For an idea of how RPN works, check out this tutorial:  http://edspi31415.blogspot.com/2011/09/rpn-basics.html


As a note, this program requires you to press the equals key [ = ] before you enter a number to the stack.  


Example:   2 + 3 + 9 = 14

Keys:

[ = ], 2, [END LINE]

[ = ], 3, [END LINE], [ + ], 

[ = ], 9,  [END LINE], [ + ]



The keys available during RPNBASIC:

[ = ] Input 

[ + ] Add: Y + X

[ - ] Subtract: Y - X

[ * ] Multiplication: Y * X 

[ / ] Divide: Y/X

[ g ] [ / ] (^) Exponent: Y^X

[ Q ]  Square Root √X

[ P ] Enter π to the stack 

[ M ] Store X in independent memory

[ R ] Recall memory 

[ C ] Clear X stack to 0


Stack operations:

[ S ] Swap with X and Y

[ D ] Roll stack down, result { Y, T, Z, X }


Exit the program: press [ E ]



HP 71B Program: RPNBASIC  (828 bytes)

5 ! SIMPLE RPN, EWS 5/12/2024

10 DESTROY S, K$

15 DIM K$, S(6)

20 OPTION BASE 1

25 DISP "RPN BASIC" @ WAIT 1

30 DELAY 0,0

35 DISP S(1)

40 K$=KEY$

50 IF K$="+" THEN S(6)=S(1)+S(2) @ GOTO 100

52 IF K$="-" THEN S(6)=S(2)-S(1) @ GOTO 100

54 IF K$="*" THEN S(6)=S(1)*S(2) @ GOTO 100

56 IF K$="/" THEN S(6)=S(2)/S(1) @ GOTO 100

58 IF K$="=" THEN 140

60 IF K$="M" THEN S(5)=S(1) @ GOTO 35

62 IF K$="R" THEN S(6)=S(5) @ GOTO 120

64 IF K$="P" THEN S(6)=PI @ GOTO 120

66 IF K$="C" THEN S(1)=0 @ GOTO 35

68 IF K$="S" THEN 160

70 IF K$="D" THEN 180

72 IF K$="Q" THEN S(1)=SQR(S(1)) @ GOTO 35

74 IF K$="^" THEN S(6)=S(2)^S(1) @ GOTO 100

76 IF K$="E" THEN 200 ELSE 40

100 ! 2 STACK OPERATION

105 S(1)=S(6) @ S(2)=S(3) @ S(3)=S(4)

110 GOTO 35

120 ! PI/RCL/INPUT

125 S(4)=S(3) @ S(3)=S(2) @ S(2)=S(1) @ S(1)=S(6)

130 GOTO 35

140 ! INPUT NUMBER

145 INPUT "NUMBER:";S(6)

150 GOTO 120

160 ! SWAP 

165 S(6)=S(1) @ S(1)=S(2) @ S(2)=S(6)

170 GOTO 35

180 ! ROLL

185 S(6)=S(1)

190 S(1)=S(2) @ S(2)=S(3) @ S(3)=S(4) @ S(4)=S(6)

195 GOTO 35

200 STOP


Examples:


Remember the order of operations! 


Example 1:

22.5 - 12.3 * 3.3 = -18.09

[ = ], 12.3, [ END LINE ],

[ = ], 3.3, [ END LINE ], [ * ],

[ = ] 22.5, [ END LINE ], [ S ], [ - ]


Example 2: (5^2 + 1.4^3)/2 = 13.872

[ = ], 5, [ END LINE ], [ = ], 2, [ END LINE ], [ g ], [ / ] (^)

[ = ], 1.4, [ END LINE ], [ = ], 3, [ END LINE ], [ g ], [ / ] (^), [ + ]

[ = ], 2, [ END LINE ], [ / ]


Example 3: π * 3.12^2 + (3.12 * 1.99) = 36.7903195271

Store 3.12 in memory. 

[ = ], 3.12, [ END LINE ], [ M ],

[ = ], 2 , [ END LINE ], [ g ], [ / ] (^),

[ P ], [ * ],

[ R ], [ = ], 1.99, [ END LINE ], [ * ], [ + ] 


Enjoy!


Note: this program can be expanded to include additional functions and calculations.  



All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 



Saturday, May 11, 2024

Spotlight: Sharp EL-T100A

 Spotlight: Sharp EL-T100A




Quick Facts



Model: EL-T100A

Company: Sharp

Timeline: Late 2010s? (guess)

Type: Desktop, Quiz (Trainer)

Power: Solar, Battery back up CR2032






I purchased this EL-T100 at an estate sale in Glendora, California, for a dollar (along with paper). The EL-100T (and the later EL-100TA) is a “Brain Exerciser”, which is designed to test speed and accuracy on arithmetic math problems.


There are three modes for the EL-100A:


Regular desktop calculator. The display has 10 digits and has the arithmetic operator indicators. We can set and store the sales tax to use in future calculations. The keys are fast and responsive.


Quiz mode: Pressing the [ Quiz ] button to choose from a set of 25 problems, 50 problems, or 100 problems. We are given two results: the accuracy and the time it took to complete the quiz.


Age mode: Pressing the [ Age ] button will test you on 25 problems. In addition to accuracy time, your brain level is measured. After two attempts, which I took recently (March 24, 2024), I scored 98% correct in 1 minute, 26 seconds, with the age score of 42. The second time, I got 96% but in 1 minute, 17 seconds, with the age score of 40. I just turned 47 last March.


Key Summary


[ +TAX ] : Adds sales tax

Set tax rate: [ C CE ] [ C CE ] tax rate [ +TAX ]


[ -TAX ]: Subtracts sales tax

Verify tax rate: [ C CE ] [ C CE ] [ -TAX ]


[ R CM ]

Once: recalls the value in the memory register

Twice: clears the memory register (sets it as 0)


[ % ] {COR. %}

Math Mode: Perform a percentage calculation

Quiz/Age Mode: Verify the stored correct ratio of answers


[ × ] {DEL.}

Math Mode: multiplication

Quiz/Age Mode: erase stored, accumulated correct answers and percentage ratio


[ + ] {RES↑}

Math Mode: addition

Quiz/Age Mode: Display the completed duration values, oldest to newest problem


[ = ] {ENTER}

Math Mode: equals

Quiz/Age mode: start a drill or obtain an answer


[ - ] {RES↓}

Math Mode: subtraction

Quiz/Age Mode: Display the completed duration values, newest to oldest problem


[ ÷ ] {RANK}

Math Mode: division

Quiz/Age Mode: display the three fasted completed duration values of the quiz


[ CA ]

Clear all calculator memory except for tax rates. Terminates Quiz and Age mode.


[ M+ ]

Add the displayed value to the memory registers


Now I’m going to work on my fast arithmetic skills.


Source


“Sharp EL-T100AB” https://www.sharpusa.com/ForBusiness/SmallElectronics/CalculatorsNew/Models/ELT100AB.aspx Retrieved 29, 2024.


The Calculator Review “Review: Sharp EL-100AB “The Brian Exerciser”” February 27, 2019. https://www.calaquin.com/2019/02/review-sharp-el-t100ab-brain-exerciser.html Retrieved March 30, 2024.



Note: Both sources talk about an updated EL-T100AB, but it is said to share the same functionality of the EL-T100A.



Eddie


All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Sunday, May 5, 2024

Circular Sector: Finding the Radius and Angle

 Circular Sector: Finding the Radius and Angle





Here is the problem:


We are given the area of the circular segment, A, and the arc length of the segment, s. What is the radius, r, and the angle, θ?


The arc length is calculated as: s = θ * r


The area is calculated as: A = ½ * θ * r^2


We have the system of equations:


A = ½ * θ * r^2

s = θ * r


Divide A by s:


A / s= (½ * θ * r^2) / (θ * r)

A / s = r / 2

2 * A / s = r


Then

s = r * θ

θ = s / r = s^2 / (2 * A)


In summary:

r = 2 * A / s

θ = s / r = s^2 / (2 * A)


Note that the angle is in radians.

Example


Example 1:

s = 4, A = 30


r = (2 * 30) / 4 = 15

θ = 4 / 15 ≈ 0.266666667


Example 2:

s = 10.5, A = 31.8


r = (2 * 30) / 4 = 212/35 ≈ 6.057142857

θ = 10.5 / (212/35) = 735/424 ≈ 1.733490566


Eddie


All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Saturday, May 4, 2024

Battle of the “Cheap” Calculators: Sharp EL-501W vs. Bazic 3003

Battle of the “Cheap” Calculators: Sharp EL-501W vs. Bazic 3003


Let’s Get Ready to Rumble!”


Today is an accuracy battle between the:


Sharp EL-501W





This is brand name calculator. In the 2010s, Sharp manufactured one with blue casing. However, their current EL-501W type (really named the EL-501XBWH) has black casing. Both the EL-501W and EL-501XBWH have the same keyboard and the same amount of functions. The average price runs from $9 to $16 (US).





This is the Bazic 3003, a clone of the Sharp EL-501W/EL-501XBWH. This model sells in discount stores for anywhere from $3 to $6 (US).


There is another clone, the Jot Scientific Calculator which is physically smaller than both models I mentioned, and is even cheaper, close it $1 to $3. (US) I won’t be using this model in today’s tests.


The features on all these models include:


* trigonometric, hyperbolic, logarithm, and power functions

* binary, decimal, octal, and hexadecimal base conversions

* two buttons, [ a ] and [ b ] which assists with complex number arithmetic and polar/rectangular conversions

* random numbers

* one-variable statistics with basic analysis



The Exchange Function: { ↕ }


The exchange key switches the operands in arithmetic calculation. The key sequence is the same: [ 2ndF ] [ ( ] { ↕ }. If we complete an arithmetic calculation by pressing the equals button [ = ], the exchange function recalls the second operand for each operation. Well, almost.


Operation

Keystrokes

Result

Addition

A [ + ] B [ = ] [ 2ndF ] [ ( ] { ↕ }

B

Subtraction

A [ - ] B [ = ] [ 2ndF ] [ ( ] { ↕ }

B

Multiplication

A [ × ] B [ = ] [ 2ndF ] [ ( ] { ↕ }

A

Division

A [ ÷ ] B [ = ] [ 2ndF ] [ ( ] { ↕ }

B

Power

A [ y^x ] B [ = ] [ 2ndF ] [ ( ] { ↕ }

B

(A, B are two arbitrary numbers)



The Sharp EL-501W has plastic keys, a slide case, and takes two LR44 batteries, while the Bazic 3033 has rubber keys, a flip case, and takes two LR1130 batteries. As a personal preference, I prefer plastic keys to rubber keys.


Let’s compare.



A Comparison of Accuracy


The Trigonometric Forensics Evaluation


This test calculates:

arcsin( arccos( arctan( tan( cos( sin( 9° )))))) (six set of parenthesis)


However, we do not need parenthesis:

[ DRG ] (press until degrees mode is set)

9 [ SIN ] [ COS ] [ TAN ]

[ 2ndF ] [ TAN ] {TAN^-1} [ 2ndF ] [ COS ] {COS^-1} [ 2ndF ] [ SIN ] {SIN^-1}


Ideally, the answer returned should be exactly 9.





This test is presented on datamath.org web site (see source below), and this test was used to determine what chips were used in various Texas Instruments calculators.


Results:

Sharp EL-501W

8.9999 98637

Bazic 3003

8.9999 9986


Bazic gets the slight edge on this test.


The Cube of a Complex Number


The next test calculates (4.5 + 2.2i)^3.


The complex number mode only works for arithmetic functions (+, -, ×, ÷).


First, lets’ calculate the cube in complex mode.


Keystrokes:

[ 2ndF ] [ → ] {CPLX} (until CPLX indicator appears)

4.5 [ a ] 2.2 [ b ] [ × ] 4.5 [ a ] 2.2 [ b ] [ × ] 4.5 [ a ] 2.2 [ b ] [ = ]


Results:

Sharp EL-501W

25.785 + 123.002i (press [ b ] for the imaginary part)

Bazic 3003

25.785 + 123.002i (press [ b ] for the imaginary part)



Now in Real Mode using the polar/rectangular conversion functions.


Keystrokes:

[ 2ndF ] [ → ] {CPLX} (until CPLX indicator disappears)

4.5 [ a ] 2.2 [ b ] [ 2ndF ] [ a ] { →rθ }

[ b ] [ x→M/STO ] [ a ] [ y^x ] 3 [ = ] (manually record 125.6756071)

[ RM/RCL ] [ × ] 3 [ = ] [ b ] 125.6756071 [ a ] [ 2ndF ] [ b ] { →xy }


Results:

Sharp EL-501W

25.78499999 + 123.002i (press [ b ] for the yi part)

Bazic 3003

25.78499999 + 123.002i (press [ b ] for the yi part)



Test of the Logarithm Bug


This test to check to the accuracy of the approximation of e^x, where


e^x = lim n → ∞ (1 + x / n) ^n


If x = 1, then e = e^x = lim n → ∞ (1 + 1 / n) ^n


This test came about because there were several TI-30X and TI-36X calculators that were manufactured in the 1990s. See the Logarithm Bug in the Sources section for more details.


At various values of n:


(1 + 1 / N)^N

Sharp EL-501W

Bazic 3003

N = 10

2.59374246

2.59374246

N = 1,000

2.716923932

2.716923932

N = 100,000

2.718268237

2.718268237

N = 10,000,000 = 1E7

2.718281693

2.718281693


Both calculators give the same results. More importantly, there is no “logarithm bug” present from these results. Yay!



Statistics of Large Numbers


Sometimes when doing statistics of large numbers, which the numbers themselves differ by little, accuracy can suffer.


The data points for this sample:

100 008

100 014

100 007

100 016

100 009

100 006

100 010

100 015

100 012

100 018


Both calculators give these results:


Mean: 100011.5

Sum: 1000115

Sum^2: 1.0002E+11 (1.000230015E+11)

σx = 3.905124838

sx = 4.116363012

n = 10



Overall, the two calculators return the same result. Based off these results, it’s down to how much money you want to spend and what type of keys do you prefer.



Sources


Woerner, Joerg. “Calculator Integrated Circuits Forensics” Datamath.org. Last updated December 12, 2001

http://www.datamath.org/Forensics.htm. Retrieved March 16, 2024.



Senzer, Bob, Mike Sebastian, and Joerg Woerner. “Logarithm Bug” Datamath.org. Last updated October 11, 2005. http://www.datamath.org/Story/LogarithmBug.htm Retrieved March 16, 2024.


For the Star Wars fans, may the Fourth and Force be with you,


Eddie


All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


Python and Calculator Basic: Determine if a Character is in a String

  Python and Calculator Basic: Determine if a Character is in a String Calculators: Casio fx-CG 50, TI-84 Plus CE Today’s blog gives a...