Showing posts with label HP 32 SII. Show all posts
Showing posts with label HP 32 SII. Show all posts

Saturday, October 5, 2024

Sum of Sequential Integers (featuring Swiss Micros DM32)

 Sum of Sequential Integers (featuring Swiss Micros DM32)


What is the sum of the following:

100 + 101 + 102 + 103 + 104 + 105 + … + 997 + 998 + 999?


It’s doable on a calculator, but going straight forward will require a lot of keystrokes (unless you have access to the sigma function (Σ)).


Note that:

100 + 101 + 102 + 103 + 104 + 105 + … + 997 + 998 + 999

= 100 + (100 + 1) + (100 + 2) + (100 + 3) + (100 + 4) + …. + (100 + 897) + (100 + 898) + (100 + 899)

= (100 + 0) + (100 + 1) + (100 + 2) + (100 + 3) + (100 + 4) + …. + (100 + 897) + (100 + 898) + (100 + 899)


Notice the sum starts with a base, 100. The sequence goes for 900 terms in the form of 100+n where n = 0 to 899. Let’s look at a general case.


Let x be a base integer, and S be the sum as:


S = (x + 0) + (x + 1) + (x + 2) + (x + 3) + …. + (x + n)


Rearranging the terms leads us to:


S = (x + x + x + x + … + x) + (0 + 1 + 2 + 3 + 4 + … + n)

There are n + 1 pairs:

S = (x * (n + 1)) + (0 + 1 + 2 + 3 + 4 + … + n)

S = (x * (n + 1)) + (1 + 2 + 3 + 4 + … + n)


The sum of Σ( k, k = 1 to k = n) = 1 + 2 + 3 + 4 + … + n = n * (n + 1) / 2


Then:

S = (x * (n + 1)) + n * (n + 1) / 2


Let’s look at some specific examples:


n = 1

S = (x + 0) + (x + 1)

S = (x + x) + (0 +1)

S = 2 * x + 1


n = 2

S = (x + 0) + (x + 1) + (x + 2)

S = (x + x + x) + (0 + 1 + 2)

S = 3 * x + 3


2 * 3 / 2 = 3


n = 3

S = (x + 0) + (x + 1) + (x + 2) + (x + 3)

S = (x + x + x + x) + (0 + 1 + 2 + 3)

S = 4 * x + 6


3 * 4 / 2 = 6


S = 500 + 501 +502 + 503

S = (500 + 0) + (500 + 1) + (500 + 2) + (500 + 3)

S = (500 + 500 + 500 + 500) + (0 + 1 + 2 + 3)

S = ((3 + 1) * 500) + (3 * 4 / 2)

S = 2000 + 6

S = 2006



S = 250 + 251 + 252 + 253 + … + 269 + 270

Base = 250

n = 270 – 250 = 20


Then:

S = 250 * (20 + 1) + 20 * 21 / 2

S = 5460


Let’s go our original problem:

S = 100 + 101 + 102 + 103 + 104 + 105 + … + 997 + 998 + 999

Base = 100

n = 999 -100 = 899

Then:

S = 100 * (899 + 1) + 899 * 900 / 2

S = 90000 + 404550

S = 494550



The program code calculates the sum:


Swiss Micros DM32 Program (also HP 32SII)


S01 LBL S

S02 INPUT X

S03 INPUT N

S04 RCL N

S05 1

S06 +

S07 RCL× N

S08 RCL N

S09 1

S10 RCL+ N

S11 ×

S12 2

S13 ÷

S14 +

S15 RTN


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, June 9, 2018

HP 32SII and HP Prime: Throwing Dice


HP 32SII and HP Prime: Throwing Dice

Note: Symbols that are produced by Unicode should, but may not show up on all browsers. Please make sure your browsers are updated to the latest version.  
⚀ ⚁ ⚂ ⚃ ⚄ ⚅

Let Em’ Roll

One way to simulate a pair of dice being thrown is to generate two random integers between 1 through 6.  The integers are either shown as a pair or vector of integers.  For calculators that do not have a list capacity or want a more compact representation, the program for the HP 32S II (which can easily apply almost to any other programming calculator), in the format A.0B, where A is one die and B is the other.   For example, 3.06 represents a 3 and a 6 being thrown.

The formula would be:   RandInt(1,6) + RandInt(1,6)/100

On certain Sharp calculators, such as the Sharp EL-W516T, the R.DICE function generates a single digit between 1 and 6.

HP 32 SII Program: Dice Generator

D01 LBL D
D02 RANDOM
D03 6
D04 *
D05 1
D06 +
D07 IP
D08 1
D09 %
D10 RANDOM
D11 6
D12 *
D13 1
D14 +
D15 IP
D16 +
D17 RTN

HP Prime:  Graphical Representation of Dice

We can also use the Unicode representation of dice.

Unicode Character
Decimal
Hexadecimal
⚀
9856
2680
⚁
9857
2681
⚂
9858
2682
⚃
9859
2683
⚄
9860
2684
⚅
9861
2685

Unicode characters need to be in strings.  The HP Prime program RDICE returns a list, the roll in compact format, along with the Unicode representation.  This is only one of many ways to do it.

An example output of RDICE is {4.02, “⚃”, “⚁”}

HP Prime Program: RDICE

EXPORT RDICE()
BEGIN
// rolling dice A.0B
LOCAL A, B, C, D;
A≔RANDINT(1,6); C≔9855+A;
B≔RANDINT(1,6); D≔9855+B;
RETURN {A+B/100, CHAR(C), CHAR(D)};
END;

Have fun and roll those dice,

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.

TI-84 Evo Basic: Half-Wave Dipole Antenna Length

TI-84 Evo Basic: Half-Wave Dipole Antenna Length Introduction The length of a half-wave antenna is calculated by: L = λ / 2 =...