Showing posts with label Casio FX-702P. Show all posts
Showing posts with label Casio FX-702P. Show all posts

Saturday, December 6, 2025

Basic vs. Python: Numeric Guessing Games (Featuring Casio fx-702P and fx-CG100)

Basic vs. Python: Numeric Guessing Games


Calculators Used


Basic: Casio fx-702P

Python: Casio fx-CG100


Task


Generate two simple number guessing games.


Guess the Number


This is the classic guess the number. The game generates a number (positive integer) at random in a given range. The player guess the number and if it doesn’t match the target number, the player is told whether the target number is lower or higher. The objective is to find the target number in the lowest number of turns.


The pricing game, The Clock Game, from the legendary game show The Price Is Right uses the Guess the Number game for two prizes. The Clock Game, the contestant needs to get the three-digit price correct for each prize within a total of 30 seconds, with the host (Drew Carey or the late Bob Barker) informing the contest whether the correct price is higher or lower.


The code is for a game where the target integer is between 10 and 99.


BASIC: Casio fx-702P


10 PRT "GUESS THE NUMBER"

20 T=INT (RAN#*90+10)

30 C=0

40 G=0


100 INP "GUESS (10-99)",G

110 IF G<10 THEN 100

115 IF G>99 THEN 100

120 C=C+1

130 IF G<T;PRT "HIGHER"

140 IF G>T;PRT "LOWER"

150 IF G=T THEN 200

160 GOTO 100


200 PRT "CORRECT! THE # IS ";T

210 PRT "# GUESSES: ";C


PYTHON: Casio fx-CG100

Script: numguess.py


from random import *


print("Guess the number ")

t=int(random()*90+10)

c=0

g=0


# != means not

while t!=g:

  g=int(input("Guess (10-99)? "))

  c+=1

  if g<t:

    print("HIGHER")

  if g>t:

    print("LOWER")


# exact guess leaves the loop


print("CORRECT! The # is "+str(t)+".")

print("# of guesses: "+str(c))


The major difference between the two programs is that the Basic version uses If statements and Goto line statements, while Python code uses a while loop.


Find the Coin


This is a guessing game where the player is tasked to find a coin in a 10 by 10 grid. The rows and columns are labeled 0 through 9.





BASIC: Casio fx-702P


10 PRT "FIND THE COIN ($)"

30 A=INT (RAN#*10)

40 B=INT (RAN#*10)

50 C=0

60 PRT "GRID 0-9,0-9"


70 INP "X (0-9)",X

80 INP "Y (0-9)",Y

90 R=ABS (A-X)

100 S=ABS (Y-B)

105 C=C+1

110 IF R=S THEN 200

120 PRT S;" ROW";R;" COL"

150 GOTO 70


200 PRT "YOU FOUND IT!"

210 PRT "SCORE= ";C


PYTHON: Casio fx-CG100

Script: findcoin.py


# find the coin, 10 x 10 grid


from random import *

print("FIND THE COIN")

# random integer from 0 to 9

a=randint(0,9)

b=randint(0,9)

c=0

print("GRID 0-9,0-9")


# set up 

r=-1

s=-2


while r!=s:

  x=int(input("X 0-9: "))

  y=int(input("Y 0-9: "))

  r=abs(a-x)

  s=abs(b-y)

  c+=1

  if r==s:

    break

  print(str(s)+" rows "+str(r)+" col")


print("You found it!")

print("SCORE= ",str(c))


Note: Both numguess.py and findcoin.py use the random module, hence it can be adopted on every calculator with a random module. The HP Prime’s random module is urandom.


Have fun, and modify as you like,


Eddie


 All original content copyright, © 2011-2025. 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.


The author does not use AI engines and never will.

Saturday, March 9, 2024

Casio FX-702P, Swiss Micros DM42, HP 27S: Design of Coil Spring

Casio FX-702P, Swiss Micros DM42, HP 27S: Design of Coil Spring


Today’s blog calculates the load of a coil spring.


Variables Used


P

LOAD

Load (kg)

G

SHEAR

Shear Modulus (kg/mm^2)

A

WDIA, W.DIA

Diameter of the wire (mm)

Y

DEFL

Deflection (mm)

N, NA

#COIL

Number of Coils

D

CDIA, C.DIA

Diameter of the coil (mm)

K = (G×A^4)÷(8×N×D)


Spring Constant (kg/mm)
(FX-702P only)



Casio FX-702P Code


The original BASIC programs are listed here (Casio, pg. 72, Program Library FX-702P, see sources):

5 FOR L=1 TO 5

10 INP “K,P:1,A:2,D:3,NA:4”,I

20 FOR J=1 TO 4

30 IF I=J THEN 100

40 NEXT J

50 GOTO 10


100 INP “G=”,G

110 G=G/8

120 IF I=2 THEN 150

130 INP “A=”,A:A=A↑4

140 IF I=3 THEN 170

150 INP “D=”,D:D=D↑3

160 IF I=4 THEN 180

170 INP “NA”=,N

180 INP “Y=”,Y

190 IF I=1;K=G*A/N/D:P=K*Y:PRT “K=”;K,”P=”;P:GOTO 240

200 INP “P=”,P

210 IF I=2;A=(P*D*N/G/Y)↑(1/4):PRT “A=”;A:GOTO 240

220 IF I=3;D=(A*G*Y/N/P)↑(1/3):PRT “D=”;D:GOTO 240

230 N=G*A*Y/D/R:PRT “NA=”;N

240 NEXT L

250 END


INP: input

PRT: print


Swiss Micros DM42 Solver Code: SPRING


Also for HP 42S, Free42, Plus42.


00 { 103-Byte Prgm }
01▸LBL "SPRING"
02 MVAR "LOAD"
03 MVAR "SHEAR"
04 MVAR "W.DIA"
05 MVAR "C.DIA"
06 MVAR "#COIL"
07 MVAR "DEFL"
08 RCL "SHEAR"
09 RCL "W.DIA"
10 4
11 Y↑X
12 ×
13 RCL× "DEFL"
14 8
15 RCL× "#COIL"
16 RCL "C.DIA"
17 3
18 Y↑X
19 ×
20 ÷
21 +/-
22 RCL+ "LOAD"
23 RTN
24 .END.


Run SPRING through the SOLVER.



HP 27S Equation: SPRING


Spaces added for readability.


SPRING: SHEAR × WDIA^4 × DEFL ÷ (8 ×#COIL × CDIA^3)



Example: Copper Spring Coil


Shear: G = 4558.131472 kg/mm^2

Coil Diameter: D = 10 mm

Wire Diameter: A = 0.7 mm

Deflection: Y = 5 mm

Number of Coils: N = 4


Result: Load: P: 0.17100 kg



Calculate the wire diameter if the load is 0.25 kg.


Result: Wire Diameter: A: 0.79672 mm



What if instead we have 8 coils? Wire diameter resets to 0.7 mm.


Result: Load: P: 0.08550 kg




Table of Shear Modulus Values


These are the shear modulus of various mediums. The higher the shear modulus is, the more rigid the solid is. If the solid’s modulus is smaller, it is easier to deform or change its shape. For liquids, the modulus is zero. The table below has two units, GPa (gigapascal) and kg/mm^2. The conversion rate is approximately 1 GPa = 101.9716212978 kg/mm^2.


The values in are from the “What is the Shear Modulus?” article by Dr. Helmenstine (see the Sources section) in GPa.


Shear Modulus

GPa

kg/mm^2

Rubber

0.0006

0.06118297278

Plywood

0.62

63.2224052

Nylon

4.1

418.0836473

Lead

13.1

1335.828239

Aluminum

25.5

2600.276343

Brass

40

4078.864852

Copper

44.7

4558.131472

Titanium

41.1

4191.033635


Source:


Casio. Program Library: FX-702P pp. 71-72 (English)

Helmenstine, Anne Marie, Ph.D. "What Is the Shear Modulus?" ThoughtCo, Feb. 17, 2021, thoughtco.com/shear-modulus-4176406. Retrieved January 21, 2024.

TranslatorsCafe.com “Convert gigapascal [GPa] to kilogram-force/millimeter² [kgf/mm²]”

https://www.translatorscafe.com/unit-converter/en-US/pressure/5-28/gigapascal-kilogram-force/millimeter%C2%B2/ Retrieved January 21, 2024



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, March 3, 2024

Casio FX-702P and Swiss Micros DM42: Spearman’s Coefficient of Rank Correlation

Casio FX-702P and Swiss Micros DM42: Spearman’s Coefficient of Rank Correlation


Introduction: Correlation of Rankings Between Two Events



The Spearman’s coefficient rank correlation tests the relationship between two variables according to the rank of the two variables. Ranks are assumed to be positive integers; 1 for 1st, 2 for 2nd, 3 for 3rd, etc. The Spearman’s correlation is said to be non-parametric, eliminating the requirement that the data is normally distributed.


The correlation has a range between -1 and +1. Two variables have a strong statistical relationship if the correlation is close to -1 or +1. Conversely, these variables have no relationship if the correlation is equal to 0.


Let the variables A and B be the two variables. Again, A and B are ranks.



Assuming that there are no ties in ranking in either A or B, the correlation is calculated as:


r = 1 - ( 6 × C)^2 ) ÷ (n^3 – n)


where:

C = Σ( (A_i – B_i)^2, k = 1 to n)

n = number of ranks


Casio FX-702P Code

This is a port of the Spearman’s Coefficient of Rank Correlation program set from Casio for the fx-702P. The original BASIC programs are listed here (Casio, pg. 89, Program Library FX-702P, see sources):



P0 (rank input):

10 C=0:N=1

20 PRT “A”;N;:INP A

30 PRT “B”;N;:INP B

40 C=C+(A-B)↑2

50 N=N+1:GOTO 20



P1 (calculate the correlation):

10 N=N-1

20 R=1-6*C/(N↑3-N)

30 PRT “R=”;R

40 END



Note: PRT and INP are shortcut commands for PRINT and INPUT, respectively. The three letter shortcuts are allowed (and encouraged) on the fx-702P.


Swiss Micros DM 42 Code: SPEAR


00 { 119-Byte Prgm }
01▸LBL "SPEAR"
02 "SPEARMAN CORR"
03 AVIEW
04 PSE
05 0
06 STO 03
07 1
08 STO 04
09 "ENTER RANK #S"
10 AVIEW
11 PSE
12▸LBL 00
13 "DONE? XEQ 01"
14 AVIEW
15 PSE
16 "A"
17 ARCL 04
18 ├"?"
19 PROMPT
20 "B"
21 ARCL 04
22 ├"?"
23 PROMPT
24 -
25 X↑2
26 STO+ 03
27 1
28 STO+ 04
29 GTO 00
30▸LBL 01
31 1
32 STO- 04
33 RCL 04
34 3
35 Y↑X
36 RCL- 04
37 1/X
38 RCL× 03
39 6
40 ×
41 +/-
42 1
43 +
44 STO 05
45 "R="
46 ARCL 05
47 AVIEW
48 .END.



Note: ├ is the append string character, call it up by pressing [ (shift) ] { ALPHA } [ ENTER ].


Instructions

1. Sort event A and B to their relative rankings. We are not analyzing data point by their values, but their rankings.

2. Press [ XEQ ] {SPEAR}

3. For each rank of event A, type the rank and press [ R/S ]. For each rank of event B, type the rank and press [ R/S ]. There are prompts to guide rank entry.

4. When done, execute label 01 by pressing [ XEQ ] 01.


Example

Two algorithms A and B are analyzed. The time between run time with algorithms A and B are:

A: 48 seconds, B: 63 seconds

A: 50 seconds, B: 64 seconds

A: 53 seconds, B: 61 seconds

A: 55 seconds, B: 66 seconds

A: 57 seconds, B: 69 seconds


Ranking the times relative to algorithm A are:

A: 48 seconds (rank 1), B: 63 seconds (rank 2)

A: 50 seconds (rank 2), B: 64 seconds (rank 3)

A: 53 seconds (rank 3), B: 61 seconds (rank 1)

A: 55 seconds (rank 4), B: 66 seconds (rank 4)

A: 57 seconds (rank 5), B: 69 seconds (rank 5)



Calculate the Spearman correlation:

XEQ SPEAR

A1? 1 R/S

B1? 2 R/S

A2? 2 R/S

B2? 3 R/S

A3? 3 R/S

B3? 1 R/S

A4? 4 R/S

B4? 4 R/S

A5? 5 R/S

B5? 5 R/S

XEQ 01

Result: R = 0.7000



The Spearman correlation is 0.7.




Sources


“Spearman’s rank correlation coefficient” DATAtab Team (2024). DATAtab: Online Statistics Calculator. DATAtab e.U. Graz, Austria. URL: https://datatab.net Retrieved January 17, 2024.


“Spearman’s rank correlation coefficient” Wikipedia. https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient Edited January 17, 2024. Retrieved January 17, 2024.


Casio. Program Library: FX-702P pg. 89 (English)

(The Casio Ledudu web page, https://casio.ledudu.com/pockets.asp?lg=eng&type=53, has the library in French).



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 42S/DM42/Free 42: Two Functions Programmed Three Different Ways

HP 42S/DM42/Free 42: Two Functions Programmed Three Different Ways Introduction In 1979, Electro Scientific Industries (esi)...