Friday, June 22, 2018

HP Prime: Feet-Inches Calculator


HP Prime:  Feet-Inches Calculator

Calculate in Feet-Inches

The program FTIN is an arithmetic calculator that calculates in feet-inches and square feet. 

At the start of the program, you will be asked to set an accuracy setting for fractions of inches.  The options available are 1/2, 1/4, 1/8, 1/16, 1/32, and 1/64.  You can change accuracy settings at any time.

Then you will be asked to enter a measurement either in feet-inches (linear) or square feet (area).   In feet-inches entry mode, you will enter the feet, whole inches, and fractional components of inches separately (see screen shot below).







When the main menu appears, your current result appears in the title screen of the choose box. 

There are eight operations included in FTIN:

1. Add ft-in:  Adds a measurement in feet-inch to the displayed value
2. Subtract ft-in:  Subtracts a measurement in feet-inch from the displayed value
3. Multiply by scalar:  Multiplies measurement by a scalar.  Use this to find the total multiple of a feet-inch measurement.
4. Divide by scalar:  Works similarly to option 3. 
5. Multiply to area:  Multiplies two lengths in feet-inch to obtain an area in square feet. 
6. Divide from area:  Divides an area by a length in feet-inch
7. Square Root from area:  Takes the positive square root of a square area.  It’s good for a finding a length of a square given its area.
8. Change accuracy settings:  Change the accuracy settings for fraction of an inch.

Option 9 is to exit the program. 

HP Prime Program FTIN

sub1();
sub2();


EXPORT FTIN()
BEGIN
// 2018-06-21 EWS

// initialization
LOCAL fx,fy,fz,ch;
LOCAL lx,ly,lz,Y,S;
LOCAL aflag,str,dh;

INPUT({{Y,
{2,4,8,16,32,64}}},
"ACCURACY DESIRED","/");
Y:=2^Y;

// initial entry
CHOOSE(dh,"Initial Units",
{"ft-in","ft^2"});
IF dh==1 THEN
fx:=sub1();
fz:=fx;
aflag:=0;
ELSE
INPUT(fx,"Enter Area","ft^2:");
fz:=fx;
aflag:=1;
END;

WHILE ch≠9 DO
fx:=fz;

// string for fz
IF aflag==0 THEN
lx:=sub2(fx,Y);
str:=STRING(lx(1))+" ft "+
STRING(lx(2))+" "+
STRING(lx(3))+" in";
ELSE
str:=STRING(fx)+" ft^2";
END;


CHOOSE(ch,str,
{"Add ft-in",
"Subtract ft-in",
"Multiply by scalar",
"Divide by scalar",
"Multiply to area",
"Divide from area",
"Square Root from area",
"Change accuracy settings",
"Quit"});


// add ft-in
IF ch==1 THEN
fy:=sub1();
fz:=fx+fy;
lx:=sub2(fx,Y);
ly:=sub2(fy,Y);
lz:=sub2(fz,Y);

PRINT();
PRINT(lx(1)+" ft "+lx(2)+
" "+lx(3)+" in");
PRINT("+");
PRINT(ly(1)+" ft "+ly(2)+
" "+ly(3)+" in");
PRINT("=");
PRINT(lz(1)+" ft "+lz(2)+
" "+lz(3)+" in");

WAIT(0);
END;

// subtract ft-in
IF ch==2 THEN
fy:=sub1();
fz:=fx-fy;
lx:=sub2(fx,Y);
ly:=sub2(fy,Y);
lz:=sub2(fz,Y);

PRINT();
PRINT(lx(1)+" ft "+lx(2)+
" "+lx(3)+" in");
PRINT("-");
PRINT(ly(1)+" ft "+ly(2)+
" "+ly(3)+" in");
PRINT("=");
PRINT(lz(1)+" ft "+lz(2)+
" "+lz(3)+" in");
WAIT(0);
END;

// multiply by scalar
IF ch==3 THEN
INPUT(S,"Enter Scalar");
fz:=fx*S;
lx:=sub2(fx,Y);
lz:=sub2(fz,Y);

PRINT();
PRINT(lx(1)+" ft "+lx(2)+
" "+lx(3)+" in");
PRINT("*");
PRINT(S);
PRINT("=");
PRINT(lz(1)+" ft "+lz(2)+
" "+lz(3)+" in");
WAIT(0);
END;

// divide by scalar
IF ch==4 THEN
INPUT(S,"Enter Scalar");
fz:=fx/S;
lx:=sub2(fx,Y);
lz:=sub2(fz,Y);

PRINT();
PRINT(lx(1)+" ft "+lx(2)+
" "+lx(3)+" in");
PRINT("/");
PRINT(S);
PRINT("=");
PRINT(lz(1)+" ft "+lz(2)+
" "+lz(3)+" in");
WAIT(0);
END;

// multiply to area
IF ch==5 THEN

fy:=sub1();
fz:=fx*fy;
fz:=ROUND(fz,6);
lx:=sub2(fx,Y);
ly:=sub2(fy,Y);
aflag:=1;

PRINT();
PRINT(lx(1)+" ft "+lx(2)+
" "+lx(3)+" in");
PRINT("*");
PRINT(ly(1)+" ft "+ly(2)+
" "+ly(3)+" in");
PRINT("=");
PRINT(fz+" ft^2");
WAIT(0);
END;

// divide from area
IF ch==6 THEN

fy:=sub1();
fz:=fx/fy;
ly:=sub2(fy,Y);
lz:=sub2(fz,Y);
aflag:=0;

PRINT();
PRINT(fx+" ft^2");
PRINT("/");
PRINT(ly(1)+" ft "+ly(2)+
" "+ly(3)+" in");
PRINT("=");
PRINT(lz(1)+" ft "+lz(2)+
" "+lz(3)+" in");
WAIT(0);
END;

// square root from area
IF ch==7 THEN
fz:=√(fx);
lz:=sub2(fz,Y);
aflag:=0;

PRINT();
PRINT("√"+fx+" ft^2");
PRINT("=");
PRINT(lz(1)+" ft "+lz(2)+
" "+lz(3)+" in");
WAIT(0);
END;

// change accruacy settings
IF ch==8 THEN
INPUT({{Y,
{2,4,8,16,32,64}}},
"ACCURACY DESIRED","/");
Y:=2^Y;
END;

END;

END;


// feet-inch-fraction entry
sub1()
BEGIN
LOCAL f,i,s,n;
INPUT({f,i,s,{n,
{2,4,8,16,32,64}}},
"ENTRY",
{"Feet: ","Inch: ",
"Frac: ","/"});
RETURN f+(i+s/(2^n))/12;
END;

// convert to feet-inch
sub2(x,y)
BEGIN
LOCAL f,i,s,t;
f:=IP(x);
i:=IP(FP(x)*12);
s:=ROUND(FP(FP(x)*12)*y,0);
t:=QPI(s/y);
RETURN {f,i,t};
END;


Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.

Saturday, June 16, 2018

Casio fx-CG 50 and HP Prime: The Price is Right Wheel Simulation


Casio fx-CG 50 and HP Prime: The Price is Right Wheel Simulation

Introduction

On the very famous game show, The Price Is Right, currently enjoying its fifth decade in its current run on television (1972-present), the hour long game show is divided into three segments.  The first two segments are played this way:

* An item up for bid is presented to four contestants who directly called from the audience.  Whoever gets closest to the actual retail price without going over wins the prize and plays a pricing game. This cycle occurs three times.

* The three winners play in a Showcase Showdown, where they spin a wheel.  The goal is obtain a score closest to one dollar without going over.  The winner advances to the final Showcase round.

The third segment is the Showcase round played by the two winners of the Showcase Showdown, where prize packages worth thousands of dollars are at stake.

This blog will present a simulation of the Showcase Showdown.  Like the game show, the amounts are shown in cents, where 100 represents one dollar. 

Single Spin Simulation:  Casio fx-CG 50

This program simulates a single spin.  The spin starts on the dollar (100) space.  The space that the pointer is in red with arrows pointed at it.  You can use the program on monochrome screens if you wish, just not type the color commands (Black, Red).

Casio fx-CG50 Program TRIPWHL1

“EWS 2018-06-12”
{100,15,80,35,60,20,40,
75,55,95,50,85,30,65,10,
45,70,25,90,5}→List 1
1 → P
For 1 → K To RanInt#(20, 60)
ClrText
MOD(P, 20) → P
MOD(P+18, 20) → A
MOD(P+19, 20) → B
MOD(P, 20) → C
MOD(P+1, 20) → D
MOD(P+2 ,20) → E
A = 0 20 → A
B = 0 20 → B
C = 0 20 → C
D = 0 20 → D
E = 0 20 → E
Black Locate 5, 2, List 1[E]
Black Locate 5, 3, List 1[D]
Red Locate 5, 4, List 1[C]
Red Locate 10, 4 “
Black Locate 5, 5, List 1[B]
Black Locate 5, 6, List 1[A]
MOD(P+1, 20) → P
.1 + .4 K → T
For .1 → I To T Step .1
Next
Next

Note:  The lines .1+.4K and the second For loop that follows it is to simulate the wheel that slows down as it spins. 

Now, if you want a complete simulation, check out the HP Prime program TPIRWHEEL.

A Showcase Showdown Round Simulation:  HP Prime Program TPIRWHEEL

The program offers two modes:

2 Player Spinoff:  This is a one spin playoff between two players. 

3 Player Normal:  This is a normal game between three players.  Each player may have up to two spins.  If the score exceeds 1 dollar, the player is out, and given a final score of 0.

When entering the names, you do not need to worry about entering the quotes.

Bonus Spins

Should a player get 1 dollar in one spin or their score from two spins add up to 1 dollar, then the player gets a bonus spin and wins $1,000.  The bonus spin always starts from the 5 cent position.  Unlike the game show, all bonus spins are taken immediately.  Landing on the green 5 cents and 15 cents spaces wins $10,000, while landing on the red dollar space on the bonus spins wins $25,000.  The amount on the bonus spin does not affect the player’s final score.

End of the Game

The end of the game will lists the players and their final scores.

HP Prime Program TPIRWHEEL
The program is over 10,000 bytes in memory. 

sbr1(); // subroutine - wheel

EXPORT TPIRWHEEL()
BEGIN
// EWS 2018-06-09
// The Price Is Right Showcase Showdown
// Simulator - Official Version
// bonus spins starts immediately
// 2 player spinoff mode (manual)

// Setup
LOCAL n,k,j,t,str1,str2,str3;
LOCAL str4,m,b;
CHOOSE(n,"Number of Players",
{"2 Player Spinoff",
"3 Player Normal"});
n:=n+1;
LOCAL players:={};
LOCAL scores:=MAKELIST(0,X,1,n);
LOCAL bonuses:=MAKELIST(0,X,1,n);

// Names
FOR k FROM 1 TO n DO
str1:="Player "+STRING(k);
INPUT({{str2,[[2]]}},str1,"Name: ");
players:=CONCAT(players,{str2});
END;

// Spin the wheel
RECT(RGB(255,255,0));
IF n==3 THEN
TEXTOUT_P("The goal is to get close to",
10,10,7);
TEXTOUT_P("$1.00 without going over.",
10,40,7);
TEXTOUT_P("You can have up to two spins.",
10,70,7);
TEXTOUT_P("Good luck!",10,100,7);
ELSE
TEXTOUT_P("This is a spinoff.",10,10,7);
TEXTOUT_P("Highest number wins.",10,40,7);
END;
TEXTOUT_P("Press any key to
continue.",10,130,7);
WAIT(0);

// spinning the wheel
LOCAL t,w,w1,w2,ch; // pointer
t:=1;

FOR k FROM 1 TO n DO

MSGBOX(players(k)+"'s 1st spin");
m:=MAX(scores);

// Inital spin
w:=sbr1(t);
t:=w(1);
scores(k):=w(2);


// test for $1 and bonus spin
IF scores(k)==100 THEN
RECT();
TEXTOUT_P(players(k)+" has $1.00!",
10,10,7);
TEXTOUT_P("$1,000 bonus!",10,40,7,
RGB(0,128,0));
bonuses(k):=1000;
WAIT(0);
// bonus spin
MSGBOX("Bonus Spin");
w:=sbr1(1);
t:=w(1); b:=0;
IF w(2)==5 OR w(2)==15 THEN b:=10000 END;
IF w(2)==100 THEN b:=25000 END;
IF b>0 THEN
str4:=players(k)+" has won $"+
STRING(b)+"!";
bonuses(k):=bonuses(k)+b;
ELSE
str4:="No bonus money.";
END;
TEXTOUT_P(str4,10,180,7);
WAIT(0);
CONTINUE; END;

IF n==3 THEN
// second spin?
str4:=players(k)+" has "+
scores(k)+" cents.";
TEXTOUT_P(str4,10,180,7);
WAIT(0);

CHOOSE(ch,
"Score to beat: "+STRING(m)+
" Spin Again?",{"SPIN","STAY"});
IF ch==1 THEN

MSGBOX(players(k)+"'s 2nd spin");

w:=sbr1(t);
t:=w(1);
scores(k):=w(2)+scores(k);

// did the player go over?
IF scores(k)>100 THEN
str4:=players(k)+" has gone over.";
TEXTOUT_P(str4,10,200,7,RGB(255,0,0));
WAIT(0);
scores(k):=0;
END;

// test for $1.00 and bonus spin
IF scores(k)==100 THEN
RECT();
TEXTOUT_P(players(k)+" has $1.00!",
10,10,7);
TEXTOUT_P("$1,000 bonus!",10,40,7,
RGB(0,128,0));
bonuses(k):=1000;
// bonus spin
MSGBOX("Bonus Spin");
w:=sbr1(1);
t:=w(1); b:=0;
IF w(2)==5 OR w(2)==15 THEN b:=10000 END;
IF w(2)==100 THEN b:=25000 END;
IF b>0 THEN
str4:=players(k)+" has won $"+
STRING(b)+"!";
bonuses(k):=bonuses(k)+b;
ELSE
str4:="No bonus money.";
END;
TEXTOUT_P(str4,10,180,7);
WAIT(0);
CONTINUE;
END;

END;

END;

// total score
str4:=players(k)+" has "+
scores(k)+" cents.";
TEXTOUT_P(str4,10,180,7);
WAIT(0);

END;


// end of the game
RECT();
TEXTOUT_P("Final Scores",10,10,7);
FOR k FROM 1 TO n DO
TEXTOUT_P(players(k)+":",10,
10+25*k,7);
TEXTOUT_P(STRING(scores(k)/100,2,2),170,
10+25*k,7);
IF bonuses(k)>0 THEN
TEXTOUT_P("$"+STRING(bonuses(k),2,0),
225,10+25*k,7,RGB(0,128,0)); END;
END;
WAIT(0);

END;


// subroutine spin the wheel
sbr1(x)
BEGIN
LOCAL wheel;

// colors
LOCAL b:=RGB(255,240,240); // snow white
LOCAL r:=RGB(255,0,0); // red
LOCAL dg:=RGB(0,255,0); // lime green
LOCAL tn:=RGB(255,208,0); // tangerine

// the wheel {{amount, color}}
wheel:=
{{100,r},{15,dg},{80,b},
{35,b},{60,b},{20,b},{40,b},
{75,b},{55,b},{95,b},{50,b},
{85,b},{30,b},{65,b},{10,b},
{45,b},{70,b},{25,b},{90,b},
{5,dg}};

// pointer
LOCAL pt,k,pm2,pm1,pc,pp1,pp2;
pt:=x;


// wheel display
FOR k FROM 1 TO RANDINT(20,60) DO
RECT();
pt:=pt MOD 20;

// display
pm2:=(pt+18) MOD 20;
pm1:=(pt+19) MOD 20;
pc:=pt MOD 20;
pp1:=(pt+1) MOD 20;
pp2:=(pt+2) MOD 20;


// box the numbers
RECT_P(74,44,164,144,0);
// borders
LINE_P(74,44,164,44,tn);
LINE_P(74,64,164,64,tn);
LINE_P(74,84,164,84,tn);
LINE_P(74,104,164,104,tn);
LINE_P(74,124,164,124,tn);
LINE_P(74,144,164,144,tn);
LINE_P(74,44,74,144,tn);
LINE_P(164,44,164,144,tn);
// side decoration - left with $
FILLPOLY_P([(28,44),(43,24),(58,24),
(73,44),(73,144),(28,144)],
RGB(255,128,0));
TEXTOUT_P("$",44,74,7,RGB(224,224,224));
// side decoration - right
FILLPOLY_P([(165,44),(180,24),(195,24),
(210,44),(210,144),(165,144)],
RGB(255,128,0));
// draw the pointer
TEXTOUT_P("<<",165,80,7,RGB(255,0,0));
// draw the numbers
TEXTOUT_P(wheel(pp2,1),95,40,7,
wheel(pp2,2));
TEXTOUT_P(wheel(pp1,1),95,60,7,
wheel(pp1,2));
TEXTOUT_P(wheel(pc,1),95,80,7,
wheel(pc,2));
TEXTOUT_P(wheel(pm1,1),95,100,7,
wheel(pm1,2));
TEXTOUT_P(wheel(pm2,1),95,120,7,
wheel(pm2,2));

// slow down the wheel
WAIT(0.08+0.01*k);
// next pointer
pt:=pt+1 MOD 20;

END;

// store results
LOCAL x1:=(pt-1) MOD 20;
IF x1==0 THEN x1:=20; END;
LOCAL x2:=wheel(x1,1);
RETURN {x1,x2};

END;

Source:

“Showcase Showdown” The Price Is Right Wiki.  Retrieved June 8, 2018.  http://priceisright.wikia.com/wiki/Showcase_Showdown

Eddie

All original content copyright, © 2011-2018.  Edward Shore.  

Saturday, June 9, 2018

HP Prime: The Money Machine Game


HP Prime: The Money Machine Game



The month of games continue…

This is a simple game where the machine randomizes between $250 to $50,000.  Press [ Enter ] whenever you feel lucky.  Good luck!

HP Prime Program GAME_MONEY

EXPORT GAME_MONEY()
BEGIN
// Money Machine random game
// 2018-03-26 EWS

// Localize variables
LOCAL K,c,d,s,lst,t1,t2,t3;

// Dark green screen (fir green)
RECT(#003000h);

// Intro screen
K:=GETKEY;
WHILE K≠30 DO
TEXTOUT_P("Are you ready to make money?",
0,0,4,#FFFF00h);
TEXTOUT_P("Then step right up, to the",
0,20,4,#FFFF00h);
TEXTOUT_P("Money Machine! Press ENTER",
0,40,4,#FFFF00h);
TEXTOUT_P("when you feel lucky! GOOD LUCK!",
0,60,4,#FFFF00h);
TEXTOUT_P("Press ENTER to continue.",
0,120,4,#00FFFFh);

K:=GETKEY;
END;

// The game
lst:={250,250,250,500,500,500,
1000,1000,1000,2000,2000,2000,2500,
2500,5000,5000,10000,15000,25000};
S:=SIZE(lst);

K:=GETKEY;
WHILE K≠30 DO
RECT(0);

// decorate
t1:=RANDINT(0,310);
t2:=RANDINT(0,310);
t3:=RANDINT(0,310);
// star is character 9733
TEXTOUT_P(CHAR(9733),t1,0,4,#FFFFFFh);
TEXTOUT_P(CHAR(9733),t2,0,4,#FFFFFFh);
TEXTOUT_P(CHAR(9733),t3,0,4,#FFFFFFh);
TEXTOUT_P(CHAR(9733),t1,200,4,#FFFFFFh);
TEXTOUT_P(CHAR(9733),t2,200,4,#FFFFFFh);
TEXTOUT_P(CHAR(9733),t3,200,4,#FFFFFFh);

// generate dollar amount
c:=RANDINT(1,S);
d:=lst[c];
// 7 is the largest font
TEXTOUT_P("$"+STRING(d),100,60,7,#00FF00h);
// wait one quarter second
WAIT(1/4);
K:=GETKEY;
END;

// Results screen
RECT(#003000h);
TEXTOUT_P("$"+STRING(d),100,60,6,#00FFFFh);
TEXTOUT_P("You won $"+STRING(d)+"!",
0,180,4,#FFFFFFh);
WAIT(0);

END;

Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.

Spotlight: Akron Brass FireCalc Pocket Computer

Spotlight: Akron Brass FireCalc Pocket Computer Welcome to a special Monday Edition of Eddie’s Math and Calculator blog. Thi...