Saturday, June 3, 2023

Carnival of Mathematics # 216

Carnival of Mathematics # 216



Welcome to a special edition of Eddie's Math and Calculator Blog.  I am once again happy to host the Carnival of Mathematics, which this is the 216th Edition.  The Carnival of Mathematics is facilitated by The Aperiodical.   

Check out the monthly series, where you can also submit articles for future carnival articles, at https://aperiodical.com/carnival-of-mathematics/.

May 2023's Carnival was hosted by Cassandra from Cassandra Lee Yieng's Blog:  https://leeyieng.wordpress.com/2023/05/01/carnival-of-mathematics-215-april-2023/

July 2023's Carnival will be hosted by Vaibhav at Double Root.  Double Root's blog:  https://doubleroot.in/

Gratitude to Ioanna Georgiou for the invitation to host once again.    




The Number 216


In a regular, non-leap year, the 216th day of the calendar is August 4.  On leap years, the 216th day is August 3. 


The digital root of 216 is 9.  (2 + 1 + 6 = 9).


The prime factorization of 216 is 2^3 * 3^3.   Note that 216 = 6^3.  


The divisors of 216 are:  1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 27, 36, 54, 72, 108, and 216.  The sum of the proper divisors are 384, making 216 an abundant number.  


216 hours is 9 days exactly.


216 can be expressed as sums and differences of powers, including:


216 = 3^5 - 3^3

216 = 2 * 10^2 + 4^2

216 = 12^2 + 9^2 - 3^2

216 = 4^4 - (6^2 + 2^2)

216 = 8^3 - (14^2 + 10^2)



The Carnival


Thank you to everyone who submitted an article.  You can submit entries at https://aperiodical.com/carnival-of-mathematics/.



SineRider 


This is a really cool game about mathematics.  The goal is to set a curve so that the snow-people successfully pass through a designated number of gates.  At first, the curves are linear but they get more challenging as the game goes on.  The game also saves your progress. (Screen shots are from the game.)






View Hack Club's intro video on Youtube:  https://www.youtube.com/watch?v=35nDYoIwiA8


Play the game here:  https://sinerider.com/




The Game of Hex:  Submitted by Massimo Dacasto





The game of Hex has two players.  The goal is to connect a string of hexagons from one side to the opposite side.  Each player claims a hexagon with their own color, such as red and blue.  The game of Hex is featured in the 1980s game show Blockbusters.  


The web page Hall of Hexagons is a gallery of moves a player can make to guarantee themselves a connection over a set number of rows.  Check out the gallery here:  https://www.drking.org.uk/hexagons/hex/templates.html.




Peirce's Law:  Jon Awbrey of the Inquiry Into Inquiry blog


This article explains Pierce's Law and provides the proof of the law.  The proof is provided in two ways:  by reason and graphically.  Simply put, for propositions P and Q, the law states:


P must be true if there exists Q such that the statement "if P then Q" is true.  In symbols:


(( P ⇒ Q) ⇒ P) ⇒ P


Article:  https://inquiryintoinquiry.com/2008/10/06/peirces-law/


The law is an interesting tongue twister to say the least.




Praeclarum Theorema:  Jon Awbrey of the Inquiry Into Inquiry blog



Jon Awbrey provides an explanation and proof of the Praeclarum Theorema, also known as the Splendid Theorem, which states:


For statements a, b, c, and d:  


((a ⇒ b) ^ (d ⇒ c)) ⇒ ((a ^ d) ⇒ (b ^ c))


Article:  https://inquiryintoinquiry.com/2008/10/05/praeclarum-theorema/



A Spiral on the Brighton Seafront:  Sam Hartburn


The place is the Brighton Seafront in Brighton, UK.  On the sea front there is a spiral of poles, which is the ratio of radii of the large circle to small circle is about the Golden Ratio ( (1 + √5) ÷ 2 ).   


See this spiral here:  https://samhartburn.co.uk/sh/maths-tourism-a-spiral-on-brighton-seafront/



Green's Windmill & Science Centre


In another travel related article, Tom, an Education Officer and blog writer of mathematics and astronomy, reviews the Green's Windmill and Science Centre in Nottingham, UK.  By the picture posted on Tom's post, this is a place I would like to visit one day.   Tom praises the Windmill for giving vision to the mathematics behind windmills, including displaying an integral equation related to electricity and magnetism:  


∫ dσ V dU/dw + ∫ dx dy dx V δU = ∫ dδ U dV/dw + ∫ dx dy dz U δV


The blog entry also features the work of George Green, a British mathematician.   


Tom's Blog Entry:  https://tommaths.blogspot.com/2023/05/greens-windmill-science-centre-museum.html


Green's Mill and Science Centre's Web Site:  https://tommaths.blogspot.com/2023/05/greens-windmill-science-centre-museum.html



Golden Integration:  John D. Cook


Speaking of the Golden Ratio, John d. Cook demonstrates Monte Carlo integration but instead of using a purely random sequence, a pseudo-random sequence using the fractional values of n * φ, where φ = ( (1 + √5) ÷ 2 ).  The method is demonstrated using Python.


Article:  https://www.johndcook.com/blog/2023/04/29/golden-integration/


Monte Carlo integration has an advantage of ease of calculation, with a cost of having to sample a large amount of points to get an accurate answer.  




A Plan to Address the World Challenges With Math:  Kevin Harnett of Quanta Magazine


The article is an interview with mathematician Minhyong Kim, Director of the International Centre of Mathematical Sciences (ICMS) in Edinburgh, Scotland.  The goal is ICMS is to focus mathematics with humanitarian studies. 


In the article, Kim emphasizes that young mathematicians want to work in diverse fields outside the traditional subjects.  


Article:  https://www.quantamagazine.org/a-plan-to-address-the-worlds-challenges-with-math-20230511/


Web page for ICMS:  https://www.icms.org.uk/


The ICMS's web page for The Mathematics for Humanity program, which has recently launched:  https://www.icms.org.uk/funding-opportunities/mathematics-humanity



Hamilton's Quaternions, or, The Trouble with Triples:  Article by James Propp


Math with a romantic story between William Rowan Hamilton and Catherine Barlow.  Hamilton's infatuation for Barlow lasted, despite the fact that Barlow was married to another man.   Barlow's son needed a tutor in mathematics, and Hamilton was the man to call.  While Hamilton was tutoring her son, he and Barlow discussed Barlow's unhappy marriage.   


Propp then details who Hamilton and Barlow first met, along with the math of quaternions in detail.  


A quaternion is defined an extended complex number represented in the form


q1 * i + q2 * j + q3 * k + q4, with q1, q2, q3, and q4 are real numbers.


When multiplying quaternions the following rules are observed:


i^2 = j^2 = k^2 = -1

i * j = k,   j * i = -k

j * k = i,   k * j = -i

k * i = j,   i * k = -j


The article:  https://mathenchant.wordpress.com/2023/05/17/hamiltons-quaternions-or-the-trouble-with-triples/



Degree of ζ(3)


Here is a stack exchange talking about the integral representation of ζ(3)  (Riemann Zeta function of 3).  As of June 2, 2023, the post has the option question regarding a degree of a group of permutations.   


The open question:  https://math.stackexchange.com/questions/4703662/degree-of-zeta3-as-a-period




I would like to thank everyone who submitted articles for the Carnival of Mathematics.  Gratitude to the Aperiodical for having me as this month's host.   


Eddie 




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

HP Prime: Integer Ratios and Integer Density

HP Prime:  Integer Ratios and Integer Density




How Many Integers Fit the Criteria?


The program INTDENS calculates the ratio of integers to a range of integer that fit a criteria.   The seven ratios that the program offers are:


1.  The number of odd integers over the range of integers


2.  The number of even integers over the range of integers


3.  The number of integers equally divisible by N over the range of integers.   The user sets the value of N.


4.  The number of perfect squares over the range of integers.  An integer is a perfect square when the fractional part of integer is zero.  Examples are perfect squares are 1, 4, 9, 16, and 25.


5.  The number of integers that begin with digit N over the range of integers.  N is the digit 0-9.   


6.   The number of integers that are triangular numbers over the range of integers.   a triangular number is an integer of the form (n * (n + 1)) / 2.


7.  The number of integers that are relativity prime to N over the range of integers.   An integer is relatively prime to N when the greatest common divisor between N and that integer is 1.   



The program can be used for testing whether density exists with the criteria.  The density, if it exists, is defined as:


limit

n → ∞    (number of integers from 0 to n-1 that fit a criteria) / (n - 1)


For example:  the integer density of odd integers is 1/2, while the integer density of integers divisible by 6 is 1/6.  Beware if the limit tends towards 0 as n gets large, such as the number of perfect squares or triangular numbers.  



HP Prime Program:  INTDENS


Code:


EXPORT INTDENS()

BEGIN

// integer density

// 2023-03-20 EWS


LOCAL A,B,C,H,I,N,lst,E;

I:=0;


// list of choices

lst:={"Odd Integers",

"Even Integers",

"Divisible by N",

"Perfect Squares",

"Begins With Digit N",

"Triangular Numbers",

"Rel. Prime to N"}; 

  

INPUT({A,B,{H,lst}},

"Integer Density",

{"LOW: ","HIGH: ","TYPE: "});  


// odd

IF H==1 THEN

FOR I FROM A TO B DO

C:=when(I MOD 2==1,1,0)+C;

END;

END;


// even

IF H==2 THEN

FOR I FROM A TO B DO

C:=when(I MOD 2==0,1,0)+C;

END;

END;


// divisible by N

IF H==3 THEN

INPUT(N,"Divisible by N","N: ");

FOR I FROM A TO B DO

C:=when(I MOD N==1,1,0)+C;

END;

END;


// perfect squares

IF H==4 THEN

FOR I FROM A TO B DO

C:=when(FP(√I)==0,1,0)+C;

END;

END;


// begins with digit N

IF H==5 THEN

INPUT(N,"Begins with digit N","N: ");

FOR I FROM A TO B DO

E:=ALOG(IP(LOG(I)));

E:=IP(I/E);

C:=when(E==N,1,0)+C;

END;

END;


// triangular numbers

IF H==6 THEN

FOR I FROM A TO B DO

E:=(−1+√(1+8*I))/2;

C:=when(FP(E)==0,1,0)+C;

END;

END;


// relatively prime to N

IF H==7 THEN

INPUT(N,"Relatively Prime to N","N: ");

FOR I FROM A TO B DO

C:=when(gcd(I,N)==1,1,0)+C;

END;

END;

 

// results

N:=B-A+1;

MSGBOX("Count: "+STRING(C)+"\n

Range: "+STRING(N)+"\n

Ratio: "+STRING(C/N)); 

RETURN QPI(C/N);  

   

END;



Examples



For this set of examples:  A = 1 (low), B = 3000 (high)


Ratio of odd integers:  1/2


Ratio of even integers:  1/2


Ratio of integers divisible by 5 (N = 5):  1/5


Ratio of perfect squares:  9/500


Ratio of integers beginning with 2:  1111/3000


Ratio of triangular numbers:  19/750


Ratio of integers relatively prime to 250 (N = 250):  2/5



Source


Diaconis, Persi and Brian Skyrms  Ten Great Ideas About Chance  Princeton University Press:  Princeton, NJ.  2018.  ISBN 978-0-691-19639-8



Note:   On June and July 2023, regular posts will be on Saturdays only.  The Carnival of Math will be on June 3, 2023.  



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

TI-Nspire CX II (CAS): How Many Terms Are Needed to Calculate π?

TI-Nspire CX II (CAS): How Many Terms Are Needed to Calculate π?



Every One Wants a Slice of π


There are many ways of calculating the π, usually apply a formula or a sequence many, many, many times to get as many digits as possible.  The file pitests.tns tests (see below) five algorithms:



Test 1:  Zeta Formula


π^2 / 6 = Σ( 1 / n^2, n=1 to ∞ )


Test 2:  Pi Squared Over Eight Sum


π^2 / 8 = Σ( (2 * n + 1)^(-2), n = 0 to ∞)


Test 3:  Half of Pi Product


π / 2 = Π( (2 * k)^2 / ((2 * k - 1) * (2 * k + 1)), k = 1 to ∞)


Test 4:  Fibonacci Number Sum


π / 2 = Σ( arctan((F_[2*k+1])^(-1)), k = 0 to ∞ )


The angle is radians.  F_[2*k+1] is the [2*k+1]th Fibonacci number.


Test 5:  Limit Sequence


π = lim (n → ∞) [ a^2 / n ]


where 

a0 = 1

a_[n+1] = a_[n] * (1 + (2 * n + 1)^(-1))


The goal is to determine how many terms are needed to obtain a certain amount of digits.  






Certain algorithms take longer than others.     Here are some results:


2 places:  3.14

3 places:  3.141



Test 1:  

2 decimal places:  600 terms

3 decimal places:  1611 terms 


The zeta function converges super slowly for small arguments.


Test 2:

2 decimal places:  199 terms

3 decimal places:  537 terms


Test 3:

2 decimal places:  493 terms

3 decimal places:  1325 terms


Test 4:

2 decimal places:  9 terms

3 decimal places: 10 terms


The Fibonacci method is the fastest and probably is the quickest way to build the expansion of π.


Test 5:

2 decimal places:  94 places

3 decimal places:  1929 places



Download the file pitests.tns here:  https://drive.google.com/file/d/1XqHtPnoKvqfmFLNWHQ-IayFz_lM5zZyT/view?usp=share_link



Source


"List of formulae involving π"  Wikipedia.   Edited on February 11, 2023.   Accessed on March 12, 2023.  https://en.wikipedia.org/wiki/List_of_formulae_involving_%CF%80



Note:   On June and July 2023, regular posts will be on Saturdays only, which will include the next Carnival of Math.


Eddie



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

Python: Square Root Simplification

 Python: Square Root Simplification



Introduction


The script SQFACTOR.py attempts to factor and simplify square root expressions in the form of either:


1.  √n

2.  √m + √n


The script was created using the TI-83 Plus Premium CE Python Edition, which is my first Python script using the French calculator.  




Python script:  sqfactor.py


from math import *

# basic code


def sqfactor(n):

  c=1

  k=2

  while k**2<n:

    while (n/k**2)-int(n/k**2)==0:

      n/=k**2

      c*=k

    k+=1

  return [c,n]


# 2 forms

print("Select: ")

print("1. sqrt(n)")

print("2. sqrt(m)+sqrt(n)")

ch=int(input())


if ch==1:

  n=float(input("n? "))

  l=sqfactor(n)

  print("sqrt("+str(n)+")=")

  print(str(l[0])+"*sqrt("+str(l[1])+")")


if ch==2:

  m=float(input("m? "))

  n=float(input("n? "))

  l0=sqfactor(m)

  l1=sqfactor(n)

  c=l0[0]

  d=l0[1]

  r=l1[0]

  s=l1[1]

  print("sqrt("+str(m)+") + sqrt("+str(n)+")")

  if d==s:

    print(str(c+r)+"*sqrt("+str(d)+")")

  else:

    print(str(c)+"*sqrt("+str(d)+")+")

    print(str(r)+"*sqrt("+str(s)+")")



Examples



Example 1:


√1640

Result:  2 * sqrt(410.0)


Example 2:


√56 + √78

Result:  2 * sqrt(14.0) + 1 * sqrt(78.0)


Example 3:


√75 + √27

Result:  8 * sqrt(3.0)



Eddie 


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

Casio Classpad fx-CP400: Solving a System of Linear Differential Equations Using Laplace Transforms

Casio Classpad fx-CP400: Solving a System of Linear Differential Equations Using Laplace Transforms



Introduction


The following procedure should work with the Casio Classpad family of calculators (300, 330, fx-CP400, fx-CP500). 


An attempt to use the Casio Classpad to solve the system of differential equations:


dxf/dt = A * xf(t) + B * yf(t) + g1(t)

dyf/dt = C * xf(t) + D * yf(t) + g2(t)


Initial conditions:  xf(0) = xf0,   yf(0) = yf0



The independent variable in all the functions is t.  The Casio Classpad's CAS functions laplace and invLaplace are used to accomplish this task.



Syntax


Laplace Transform of f(t):


laplace(f(t), t, s)


Laplace Transform of a Differential Equation:


laplace(diff eq, independent variable, dependent variable, s)


Inverse Laplace Transformation:


invLaplace(ℒ(s), s, t)


t:  parameter of the original function f(t)

s:  parameter of the transformed function ℒ(s)


The definition of a Laplace Transformation:


ℒ(f(t))(s) = ∫( f(t) * e^(-s*t) dt, t = 0 to ∞)


Now, even though we are working a system of differential equations, the laplace and invLapace commands can only work on function at a time.  Any other variable will be treated as a constant, even it was meant to represent another functions.  The substitution steps will account for this.  


The variables used to respect the Classpad's system variables.  


Here are the steps I used to solve:


dxf/dt = A * xf(t) + B * yf(t) + g1(t)

dyf/dt = C * xf(t) + D * yf(t) + g2(t)


Initial conditions:  xf(0) = xf0,   yf(0) = yf0


Spaces are added to readability.  



1.  Store dxf/dt in the variable f1.   Use xf' to represent dxf/dt.  


2.  Store dyf/dt in the variable f2.   Use yf' to represent dyf/dt.


3.  Execute the following and substitutions:


laplace( f1, t, xf, s ) ⇒ g1

g1 | xf(0) = xf0 and  yf / s = Mp ⇒ g1


4.  Execute the following and substitutions:


laplace( f2, t, yf, s ) ⇒ g2

g2 | yf(0) = yf0 and Lp = Mp ⇒ g2

g2 | xf /s = Lp ⇒ g2


Note Lp = ℒ( xf(t) ) and Mp = ℒ( yf(t) )


5.  Now solve the system of transformed equations: 


solve( {g1, g2}, {Lp, Mp} ) ⇒ lists


6.  Take the inverse laplace transforms:


invLaplace( getRight( lists[1], s, t ) ) ⇒ h1

invLaplace( getRight( lists[2], s, t ) ) ⇒ h2


The solutions are:


xf(t) = h1

yf(t) = h2


The getRight command extracts the right side of an equation.



Examples


Example 1:


xf ' = -0.08 * xf + 0.02 * yf + 6

yf ' = 0.08 * xf - 0.08 * yf


Initial conditions:  xf(0) = 0, yf(0) = 150






Example 2:


xf ' = 2 * xf + yf + t^2

yf ' = -2 * xf + 5


Initial conditions:  xf(0) = 2, yf(0) = 5




Casio Classpad Program:  laplaced


Download here:  https://drive.google.com/file/d/1zxTEynCjXmBrPU9pYqmXo3kF_so7fiI-/view?usp=share_link


Code:


' setup

SetRadian


' local variables

Local str1, str2, f1, f2

Local g1, g2, lists, h1, h2

Local Mp, Lp, t, s, xval, yval


' main

ClrText

InputStr str1, "xf'(xf,yf,g1(t))="

InputStr str2, "yf'(xf,yf,g2(t))="

Input xval, "xf(0)? "

Input yval, "yf(0)? "


StrJoin "xf'=", str1, str1

StrJoin "yf'=", str2, str2

strToExp(str1) ⇒ f1

strToExp(str2) ⇒ f2


' transform and solve

laplace(f1, t, xf, s) ⇒ g1

g1 | xf(0) = xval and yf/s = Mp ⇒ g1


laplace(f2, t, yf, s) ⇒ g2

g2 | yf(0) = yval and Lp = Mp ⇒ g2

g2 | xf/s = Lp ⇒ g2


Print "Laplace Transforms:"

PrintNatural g1

Print g1

PrintNatural g2

Print g2


solve({g1, g2},{Lp, Mp})⇒lists

invLaplace(getRight(lists[1]),s,t) ⇒ h1

invLaplace(getRight(lists[2],s,t) ⇒ h2


Print "Solutions: "

Print "xf = "

PrintNatural h1

Print h1

Print "yf = "

PrintNatural h2

Print h2


Note:  PrintNatural displays the expression in textbook form in a popup box, but it does not add anything to the text output terminal.  This is why I included both PrintNatural and Print commands.  



Source


Kreyszig, Erwin.  Advanced Engineering Mathematics  8th Edition  John Wiley & Sons, Inc:  New York, NY.  1999.  ISBN 0-471-15496-2



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

Monday, May 15, 2023

TI-84 Plus CE and TI-83 Premium CE: Vectors Program

TI-84 Plus CE and TI-83 Premium CE:  Vectors Program










The program VECTORS is made for the TI-84 Plus CE and TI-83 Premium CE.  


Introduction


The program VECTORS calculates the following of the three dimensional vectors [A] and [B]:


* Dot product of [A] and [B]

* Euclidean norm of vectors [A] and [B]

* Angle between vectors [A] and [B] in degrees

* Cross product of [A] × [B]

* Tensor product of [A] ⊗ [B]


The program uses the system matrices [A] and [B] and formats them as 3 rows, 1 column matrices.   The program changes the angle mode to Degrees.


After entering each vector, the program gives you an option to normalize the vectors.  Since the cross and tensor products do not follow the commutative property, there is an option to switch the elements of both vectors.  


Depending on the calculator used, results will be shown in either exact format (TI-83 Premium CE) or approximate format (TI-84 CE).  



Calculations Used 


In this section, each of the vectors will be followed by the program code used.  


Let [A] and [B] be the column vectors:

[A] = [[a1][a2][a3]]

[B] = [[b1][b2][b3]]


Dot Product: 

[A] • [B] = a1 * b1 + a2 * b2 + a3 * b3 = [A]ᵀ [B]




Euclidean Norm:

||[A]||₂ = √(a1² + a2² + a3²) = √([A]ᵀ [A])

||[B]||₂ = √(b1² + b2² + b3²) = √([B]ᵀ [B])





Angle Between Two Vectors:

θ = arccos(([A] • [B]) ÷ (||[A]||₂ * ||[B]||₂))




Cross Product:

[A] × [B] = [C] where:

c1 = a2 * b3 – a3 * b2

c2 = -a1 * b3 + a3 * b1

c3 = a1 * b2 – a2 * b1

The result is a 3 x 1 matrix. 




Tensor Product:

[A] ⊗ [B] = [A] [B]ᵀ

The result is a 3 x 3 matrix. 





Download 



You can download the program and the user guide here:

https://drive.google.com/file/d/1R1sHGfr8dKQDkH87QDE0HgMDWxeLNHPN/view?usp=share_link



Eddie 



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

HP Prime: Drawing a Balance Scale and an Updated High Low Game

HP Prime:   Drawing a Balance Scale and an Updated High Low Game



Introduction


The program DSCALE draws a balance scale given two weights:  one placed on the left side (A) and one on the right side.  The length of the bar, which is measured from the center to one of the weights can be set by the user.   Assume that the length is equal on both sides.


The scale in this program is not meant to bend more than 45°.   The program will not draw the scale if the bend is greater than 45°.  


The program is made to simulate balancing the scales.   


Note that the HP Prime PPL  (Prime Programming Language) does not have goto and label commands.  To allow for the user to draw more than one scale, a while loop and a seeding value are used.



HP Prime Program:  dscale


EXPORT dscale()

BEGIN

STARTAPP("Function");

HAngle:=1;  // degrees

W:=4;

K:=1;

INPUT(L,"Balance Scale","L:",

"Length-Center");

 

  

WHILE K==1 DO

INPUT({A,B},"Balance-Scale",

{"<-","->"},{"Left Weight","Right

Weight"});

D:=(B-A)/2;

θ:=ABS(ATAN((B-A)/L));

S:=W*(B-A)/L;

IF θ>45 THEN

MSGBOX("CANNOT DRAW");

CONTINUE;

END;

Function.Xmin:=−W-1;

Function.Xmax:=W+1;

Function.Xtick:=1;

Function.Ymin:=−W-1;

Function.Ymax:=W+1;

Function.Ytick:=1;

RECT(#FFFFFFh);

LINE(0,W,0,−W,#DAA520h);

LINE(−.5,W,.5,W,#FF8000h);

LINE(−1,−W,1,−W,#FF8000h);

LINE(−.5,W,−W,S,#AAAAAAh);

LINE(.5,W,W,−S,#AAAAAAh);

LINE(−W,S,W,−S,0);

WAIT(0);


CHOOSE(K,"Again?","Yes","No"); 

END;

STARTVIEW(−1);

 

END;






The Hi-Low Game Comes to the HP Prime



The program HILODS is the classic high-low guessing game, but instead of text, it draws a balance scale to indicate whether you are higher and lower from the target number.  You work with the left weight (A), with the goal of balancing with the right weight (B).  The right weight is set with a random integer from 10 to 99.  


The game has three difficulty levels:  easy (25 guesses), medium (15 guesses), and hard (10 guesses).






HP Prime Program:  hilods


lose()

BEGIN

STARTVIEW(−1);

MSGBOX("The number is "+STRING(B)+".\n

"+STRING(ABS(A-B))+" away.\n

Better luck next time.");

// backslash n: new line

END;


win() 

BEGIN

STARTVIEW(−1);

MSGBOX("You win! \n

# Guesses: "+STRING(N-C));

END;

 

EXPORT hilods()

BEGIN

// in progress

 

  

STARTAPP("Function");

HAngle:=1;  // degrees

W:=4;

L:=100;

B:=RANDINT(10,99);

Function.Xmin:=−W-1;

Function.Xmax:=W+1;

Function.Xtick:=1;

Function.Ymin:=−W-1;

Function.Ymax:=W+1;

Function.Ytick:=1;

CHOOSE(I,"Different Levels",

"Easy","Medium","Hard");

C:=2.5*I^2-17.5*I+40;

N:=C;

A:=0; // starting seed


WHILE A≠B DO

INPUT(A,

"Guesses left: "+STRING(C),

"Guess? ",

"From 10 to 99");

D:=(B-A)/2;

S:=W*(B-A)/L;

RECT(#FFFFFFh);

LINE(0,W,0,−W,#DAA520h);

LINE(−.5,W,.5,W,#FF8000h);

LINE(−1,−W,1,−W,#FF8000h);

LINE(−.5,W,−W,S,#AAAAAAh);

LINE(.5,W,W,−S,#AAAAAAh);

LINE(−W,S,W,−S,0);

WAIT(0);

C:=C-1;

IF A==B THEN

win();

END;

IF C==0 THEN

lose(); B:=A; // to exit loop

END;

// while end

END;

// main end

END;





This a slightly different approach to the same program than I gave last week.  


Eddie 



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


Carnival of Mathematics # 216

Carnival of Mathematics # 216 Welcome to a special edition of Eddie's Math and Calculator Blog.  I am once again happy to host the Carni...