Sunday, April 27, 2014

Combinations: Arranging Permutations with Three Ascending Consecutive Numbers

Question:  How many ways can a digits of a number be arranged so that at least three digits are in (i) ascending order and (ii) consecutive positions?

The Number 1234 (4 digit numbers)

Question:  How many ways can I arrange the digits of the number 1234 so that each permutation has at least three digits are in (i) ascending order and (ii) consecutive positions?

For example, desired permutations are 1234, 2134, and 4123.


The requirements that three digits are in ascending and consecutive order are be satisfied if the permutation contains any of the following:  123, 124, 134, and 234.

Treat the mentioned permutations as one object and the remaining number as one. Three slots has the group 123, 124, 134, and 234.  The corresponding last digit for each of the group is 4, 3, 2, and 1, respectively.  The number of arrangements so far is 4 * 2 = 8.   We are not done though.  Here are the eight arrangements calculated:


Note that 1234 appears twice.  Let's remove the duplicate.   We are left with 4 * 2 - 1 = 7. A table of all possible arrangements of 1234 (with the desired permutations highlighted). 

The Number 12345 (5 Digits)

Let's address the same question, this time with the arranging the digits of 12345.

The requirements that three digits are in ascending and consecutive order are be satisfied if the permutation contains any of the following:  123, 124, 125, 134, 135, 145, 234, 235, 245, and 345.  There are 10 three-digit combinations. 

Like before, treat the three digit combinations as "one object" and the two remaining digits separately.  For example, the combo 124 will fill three digits, 3 and 5 will complete the other two digits.  The gross number of permutations are (10 * 3) * 2 * 1 = 60.  Like the last problem, we have to account for duplicates.  In those 60 permutations counted, 12345, 12354, 12453, 13452, 23451, 21345, 51234, 41235, 31245 are counted twice, and 12345 counted thrice.  Removing 10 duplicate permutations, we arrive at our final answer: 60 - 10 = 50.

The complete calculation is:  (10 * 3) * 2 * 1 - 10 = 50.

A table of all possible arrangements of 12345 (with the desired permutations highlighted) is shown below:

I am not 100% sure if there was a formula for answering this question - but here is a way to find such arrangements using brute force.  What inspired me to do pursue this question was this video published by Numberphile: 

In this video, Simon Pampena arranges nine numbered cards and addressed how often those cards are arranged with at least four cards are in ascending or descending order.  However, Pampena does not the requirement that the ordered cards are arranged in consecutive slots.  

BTW, I am back from Seattle in Southern California.  

Have a great weekend - the rest of it - and I'll talk to you next time!



Thursday, April 24, 2014

Greetings from Seattle - and a short review of the PCalc App. (Updated 4/28/2014)

I am in at the 1st Ave and Pike St Starbucks: the original Starbucks. Actually, the first one opened that first opened in 1971 moved to this location in 1976. The original Pike Place Brew is strong! Thankfully the coffee mellows after a while.

It is a dream of mine to blog from here. Thank you Starbucks! (Twitter: @starbucks)

Short Review of PCalc

This was recommend to me by bb010g. Thanks for the recommendation!

PCalc Lite: Free (basic scientific calculator - Algebraic and RPN modes)
PCalc Full: $9.99 on iOS. (Includes Engineering functions, additional themes, conversions, programmer pack - base conversions and Boolean logic - each can be purchased separately)

Also available on Mac, but not available on Android devices.

Developer: James Thomson (Twitter: @jamesthomson)

I have the full version on both my iPad and iPod Touch. I like the intelligent layout of the keyboard, especially on the iPod Touch. The keys are big but you can still access all the major functions without much trouble. The choice of settings are plenty: everything from calculator settings to whether sound the keys make, if at all.

The features such as conversions, constants, and custom functions are accessed through the A>B, 42, and f(x) keys respectively. Each of the menus offers its options in a style consistent to standard iOS devices.

The calculator app has 10 memory registers and 16 other temporary registers that are used for programming. You can program custom functions. While the language does not contain loops, it does include relational testing (if true then skip n steps). Instead of working with the stack, you work with the memory and temporary registers, which takes a little getting used to. I hope to publish future posts explaining PCalc programming language in detail in the near future.

Here is a little sample of snippets I learned with the PCalc Programming:

The commands are constructed using proper English. (e.g. "Multiply M3 by M1", "Set R0 to 22/15")

Arithmetic Operators: Execute (add, subtract, multiply, divide) on a designated register with a certain value. The result is stored in the designated register.

Register X is the "display". Use this register to display your final answer. (Assuming your function has only one output).

To take the absolute value (on register X for example), execute the following steps:
Power X by 2
Power X by 0.5

PCalc is a great calculator app worth looking into. Website:

Update 4/28/2014:

Thanks to Terry for alerting me to this:  In Radians mode, cos(1.57079632) returned an answer of 6.7948967066 x 10^-9, which is not accurate.  Checking with Wolfram Alpha and with several calculators (HP 32Sii for example), cos(1.57079632) returns the correct answer of 6.7948966... x 10^-9.   Hopefully, this gets corrected in the next update.  

I checked cos(pi/2) and PCalc was accurate with answer of 0.

This ends my blog entry for now - off to see Seattle! Talk to you all soon! Thanks for the comments, recommendations, corrections, and compliments. As always, they are much appreciated.


This blog is property of Edward Shore. 2014

Sunday, April 20, 2014

HP Prime: EC and BLOTCH - two programs using MOUSE and DRAWMENU

Happy Easter!
Happy 4/20 Day!
Happy Sunday!

These two programs for the HP Prime illustrate the use of DRAWMENU and MOUSE.


Using DRAWMENU to draw a customized menu.

Functions featured:
head: 1st element of a list
tail: all elements of a list except the 1st
l2norm: L-2 norm of a vector
ker: kernel of a matrix
SPECRAD: spectral radius of a matrix
even: is the number even?

Input: EC(argument)

The argument needs to be appropriate type of what you want to do.

For head and tail: the argument needs to be a list.
For l2norm: the argument needs to be a vector.
For ker and SPECRAD: the argument needs to be matrix
For even: we need an integer

EC({7,8,9}), choosing head will return {7} while tail returns {8,9}.
EC([7,2,6,9]) while choosing l2norm returns √170.
EC([[1,4],[-3,-12]]) while choosing ker returns [[4, -1]].
EC([[1, 4],[-3, -12]]) while choosing SPECRAD returns 13.0384048104 (approximately)
For even, a result of 1 indicates that the number is even and 0 if the number is odd.


// CAS Custom Menu
// EWS 2014-04-20

LOCAL m,m1,mx,my;
TEXTOUT_P("Choose the function.",1,1,4);
TEXTOUT_P("head: 1st element of a list",1,18,4);
TEXTOUT_P("tail: all elements of a list except the 1st",1,35,4);
TEXTOUT_P("l2norm: L-2 norm of a vector",1,52,4);
TEXTOUT_P("ker: kernel of a matrix",1,69,4);
TEXTOUT_P("SPECRAD: spectral radius of a matrix",1,86,4);
TEXTOUT_P("even: is the number even?",1,103,4);



IF my≥220 AND my≤239 THEN

IF mx≥0 AND mx≤51 THEN
RETURN SUB(x,1,1);

IF mx≥53 AND mx≤104 THEN

IF mx≥106 AND mx≤157 THEN
RETURN exact(ABS(x));

IF mx≥159 AND mx≤210 THEN
RETURN ker(x);

IF mx≥212 AND mx≤263 THEN

IF mx≥265 AND mx≤319 THEN
RETURN even(x);




Blotch Drawing Program

S = size of the square blotch
D = size of each box in the blotch. Each box is a randomized color.

To draw a square blotch, just touch the screen outside the menu.

Input: BLOTCH( )


// EWS 04-20-2014

// Initialize
LOCAL m,m1,mx,my,j,k,r;

// Clear Canvas
LOCAL s:=50, d:=4;

// Menu - to be redrawn

// Start main loop

// Get mouse data
m:=MOUSE; m1:=m(1);
mx:=m1(1); my:=m1(2);


// Clear Screen
IF (my≥220 AND my≤319) AND (mx≥0 AND mx≤51) THEN

// Change Size
IF (my≥220 AND my≤319) AND (mx≥53 AND mx≤104) THEN
IF s<80 THEN s:=s+5; END;

IF (my≥220 AND my≤319) AND (mx≥106 AND mx≤157) THEN
IF s>5 THEN s:=s-5; END;

// Change Depth
IF (my≥220 AND my≤319) AND (mx≥159 AND mx≤210) THEN
IF d<8 THEN d:=d+2; END;

IF (my≥220 AND my≤319) AND (mx≥212 AND mx≤263) THEN
IF d>2 THEN d:=d-2; END;

// Exit Key
IF (my≥220 AND my≤319) AND (mx≥256 AND mx≤319) THEN

// Draw Blotch
FOR j FROM mx-s/2 TO mx+s/2 STEP d DO
FOR k FROM my-s/2 TO my+s/2 STEP d DO

// Close main loop
UNTIL (my≥220 AND my≤319) AND (mx≥256 AND mx≤319);


As always, thank you for your comments, compliments, and questions. Happy Sunday everyone!

I will be heading to Seattle later this week - hope to blog from the Original Starbucks when I am there.

This blog is property of Edward Shore. 2014

Thursday, April 17, 2014

MAA Southern California-Nevada Section Spring Meeting: Highlights


On April 12, 2014, I went to the Southern California-Nevada Section of the MAA Spring Meeting, held at Concordia University in Irvine, CA. It has been more than ten years since I last went to a meeting. It feels good to go back.

Link on to their website:


Hal Stern, University of Redlands talked about how statistics play a significant role in sports, and how it can be useful in measuring and predicting performance.

A student poster session, which lasted an hour. Given how excellent and engaging the student's posters were, I was only able to look at four in the hour given for the poster sessions, and I only wished that I looked at more.

After the poster session, Rachel Levy of Harvey Mudd College, spoke about her journey as a mathematician deals with the media. She states that good incidental communication is important because it form an impression on anyone who is listening.

Levy starts by emphasizing the need for mathematicians to communicate and be aware of how they communicate. Harvey Mudd requires all math majors take a public speaking class. The class has shown to have positive affects on her students. Levy also emphasize the use affirmations, such as saying to students "You are thinking like a math major," leading students to believe that they can join the mathematics community.

Levy stresses the need for positive communication. She challenges the often used saying "So easy even your grandmother can do it," implying the referred groups are seen as novices. This inspired her to start her blog, Grandma got STEM, which highlights grandmothers and their mathematical and scientific accomplishments. After communication with a librarian, her blog gained a significant increase in readers, leading to radio interviews world-wide.

Link to Grandma got STEM:

Levy talked about how Twitter can be used to advertise positive messages regarding mathematics, advertising math blogs and events, and send thank you notes.

In the final part of the presentation, Levy describes her dealings with the general press, stating it is a risky proposition, as the press can easily distort the intended message (either intentionally or unintentionally). She gives tips include having your talking points prepared, thinking about the audience, having photographs and videos ready, and making sure the one takeaway point is said during the interview.

This is my favorite part of the spring meeting.

The next talk was given by Perla Myers, University of San Diego. Myers describe her mission to change the prevailing feelings of fear and distraught when people think of mathematics. She specializes in training future teachers to enhance mathematical understanding and introduce activities designed to make learning math enjoyable, such as the use of origami.

Jamie Pommersheim, Reed College, gave he final talk of the day. The topic: dissecting squares into triangles of equal areas.

It is possible to accomplish this task by using an even number of triangles, but what about odd number of triangles? This question was first addressed by Fred Richman, who at first posed this questions to his students. After finding out the difficulty of this task, he turned the question to American Mathematical Monthly publication.

It was later proved by Paul Monsky that splitting the square into an odd number of triangles of equal area was impossible. Pommersheim devoted the rest of his talk to describe why, using two approaches.

The first approach describes Monsky's proof. Pommersheim starts by describing the 2-adic norm which is described by:

|| n || = || 2^t * r/s || = 2^(-t)

Where n is a rational number, and r and s are odd integers. The 2-adic norm of 0 is defined to be 0.

Examples of calculating the 2-adic norms:
|| 6 || = || 2^1 * 3 || = 1/2 (t = 1)
|| 16 || = || 2^4 || = 1/16 (t = 4)
|| 5/8 || = || 1/8 * 5/1 || = || 2^(-3) * 5 || = 8 (t = -3)

Consider a square with corner points (0,0), (1,0), (1,1), and (0,1). Each corner point and any point that helps form triangles within that square is assigned a "color". For each point (x,y), the color is assigned as follows:

The color A is assigned if:
* x has the largest 2-adic norm or
* x at least as big of 2-adic norm of either y or 1.

The color B is assigned if:
* y has the biggest 2-adic norm or
* the 2-adic norm of y is 1 and x has a 2-adic norm is less than 1.

The color C is assigned if both x and y have 2-adic norms less than 1.

For the corner points, the following colors are assigned:
(0,0) has the color C
(1,0) has the color A
(1,1) has the color A
(0,1) has the color B

It is next shown that three collinear points cannot have all three colors A, B, and C. Consider the three points (0,0), (x1, y1), and (x2, y2). Point (0,0) is assigned the color C.

The area of a general triangle can be calculated by:

Area = 1/2 * det([[x1, y1, 1],[x2, y2, 1],[x3, y3, 1]])

Using this formula above, the "area" is x1*y2 - x2*y1. We know the area of any line is 0. Hence, x1*y2 - x2*y1 = 0. And:

Show that a straight line can contain points of only two colours.

x1*y2 = x2*y1

Taking the two 2-adic norms of both sides to get:

|| x1*y2 || = || x2*y1 ||
|| x1 || * || y2 || = || x2 || * || y1||

This implies that both points must be assigned the same color which contradicts the assumption that a line made of three collinear points can have three different colors.

The proof goes on to use Sperner's Lemma, which states (briefly) given any dissection of square there exists of a tricolored triangle. Also, the 2-adic norm of an area of tricolored triangle is greater than 1. However, if the square is divided into an odd number of triangles, the 2-adic norm of each triangle is 1.

Pommersheim shows a second way to demonstrate that squares cannot be cut into an odd number of equal area triangles. He uses finds a polynomial of areas that is associated with each dissection.

For a square dissected into four triangles, the associated polynomial is
D + B - (A + C), which A, B, C, and D represent the areas for each triangle. In this case each area of the triangle is n/4 where n is the area of the square. Clearly, n/4 + n/4 - (n/4 + n/4) = 0, which is the desired result.

For a square dissected into six triangles the polynomial becomes:
(A + C + E)^2 - 4*A*B - (B + D + F)^2 + 4*D*F.

Substituting n/6, the area of each triangle in this case, and the value of the polynomial is 0.

Pommersheim eliminates triangle B. Now we have five triangles, each with area n/5. The polynomial becomes:
(A + C + E)^2 - 4*A*C - (D + F)^2 + 4*D*F

The trouble comes when we evaluate the polynomial with each area n/5, which leaves the value n^2/5. This shows that it is impossible to divide a square into an odd number of triangles of equal area.

There it is. I hope you find this enjoying, informational, and inspiring. I look forward to going to the next one. Until next time,


This blog is property of Edward Shore. 2014

HP Prime Video: Scatterplots

A simple video on how to plot scatter plots on the HP Prime:

This blog is property of Edward Shore. 2014

Monday, April 14, 2014

Program - HP 32SII: Stopping Sight Distance

Background: The stoping sight distance is the distance traveled when a person operating perceives the need to the stop and stops the vehicle. The velocity used in calculating stopping sight distance is the referred to as the design speed. The stopping sight distance is the sum of two parts:

1. Reaction Distance, which is the distance while the operator perceives the need to stop, and

2. Breaking Distance, which is the distance traveled while the operator puts the breaks on the vehicle, slowing the vehicle to a stop.

The general formula is:

SSD = v * t_r + v^2/(2*(a + g*G))

v = the design speed of the vehicle
t_r = perception-reaction time
a = deceleration rate of the vehicle
g = gravity constant (32.174 ft/s^2 or 9.80665 m/s^2)
G = grade of the road. Grade is positive for uphill roads. If a road has a grade of 1%, it means for every 100 ft travelled horizontally, the road has risen 1 ft. In this formula, grade is given as a percentage (i.e. 1%, G = 1)

The AASHTO (American Association of State Highway and Transportation Officials) recommends t_r = 2.5 seconds and a = 11.2 ft/s^2.

The formula for SSD using U.S. units and recommended constants is given as:

SSD = 55/15 * v + (1.075*v^2)/(11.2 + 0.32*G)

Where velocity is given in mph. The HP 32sII program given below has the U.S. Formula.

Source: Goswami, Indramil Ph.D. P.E. "All In One Civil Engineering PE Breadth and Depth Exam Guide" 2nd Edition. McGraw Hill: 2012



Y: speed of vehicle or design speed (mi/hr)
X: grade of the road (i.e. for 1% grade enter as 1)


X: Stopping Sight Distance (in feet)

Formula used:
SSD = 55/15 * V + 1.075*V^2/(11+.32*G)

* Total reaction time is 2.5 seconds. The deceleration rate of the vehicle is 11 ft/s^2. Both values are recommended by the AASHTO (American Association of State Highway and Transportation Officials).


S02 0.32
S03 *
S04 11.2
S05 +
S06 1/x
S07 1.075
S08 *
S09 x<>y
S11 R-down
S12 x^2
S13 *
S14 R-up
S15 55
S16 *
S17 15
S18 ÷
S19 +


Y: 65 (V)
X: 2 (G)
Result (Fix 4): 621.9376 ft

Y: 35 (V)
X: -4 (G)
Result: 261.0828

This blog is property of Edward Shore. 2014

Thursday, April 10, 2014

BASIC Programming Language Turns 50 on May 1

Thanks to Don Shepherd sharing this at the MoHPC website, here is the information regarding BASIC's 50th birthday! The programming language was born at Dartmouth College in Hanover, NH. John Kemeny and Thomas Kurtz were the original developers.

#programming #math

This blog is property of Edward Shore. 2014

Wednesday, April 9, 2014

Video: Calculating NPV, NFV, NUS using (most) any financial calculator

In this video I demonstrate on how to calculate net future value (NFV) and net utility stream (NUS) using any financial calculator with NPV (net present value) and TVM (time value of money) worksheets.



This blog is property of Edward Shore. 2014

Saturday, April 5, 2014

Video: FILLPOLY command for the HP Prime

A new video has been posted!

Syntax for the FILLPOLY command:

FILLPOLY(points, color, alpha*)

FILLPOLY_P(points, color, alpha*)

points: a list of vertices {x_1, y_1, x_2, y_2...}
color: either a hexadecimal integer #RRGGBBh or use the RGB command
alpha: transparency factor, 0 to 255 (optional)


This blog is property of Edward Shore. 2014

Friday, April 4, 2014

Civil Engineering Notes: Transportation

Source: Goswami, Indramil Ph.D. P.E. "All In One Civil Engineering PE Breadth and Depth Exam Guide" 2nd Edition. McGraw Hill: 2012

Over the last year or so, the topic of civil engineering has fascinated me. While I don't expect to study for the Civil Engineering exam I wanted to get some sort of an encompassing resource that I learn a few things from in a desire to better understand some facets of engineering. I ended up purchasing a Kindle Edition of the All In One Civil Engineering book primarily because I felt it provided me with the best bang for the buck. Plus it was a better alternative to get a newer edition electronically for half of what I would have paid for a first edition of physical book. From time to time, I plan to post some notes of what I read.

This post is regarding transportation.


Trip Generation: the number of trips made on a network. The network is implied to be made of zones. Zones are small areas that are determined by population, employment, or other given measurement, which are said to be anywhere from 1/4 square mile to a full mile. Trips are said to original from one designated zone (trip producer) to a destination zone (trip attractor).

Time Mean Speed (S_T): the arithmetic mean of speeds of vehicles passing over a given point. Let s_1, s_2, ... , s_n be the speeds of passing vehicles. Then the time mean speed is:

S_T = (s_1 + s_2 + ... + s_n) / n

Space Mean Speed (S_R): the average mean speeds with delays taken into account. This is theorized by taking the harmonic mean of speeds of vehicles passing over a given point. A mathematical definition is:

S_R = n / (1/s_1 + 1/s_2 + ... + 1/s_n)

Note that this is not the only way to calculate space mean speed. Using the strict definition:

S_T = total distance ÷ total time including stops and delays

In general, S_R ≤ S_T.

Consider two speeds A and B, assuming A and B are positive. Then:

S_T = (A+B)/2 and

S_R = 2/(1/A +1/B)
= 2 * (A+B)/(A*B)

Setting S_T and S_R equal to each other yields:

1/2 * (A+B) = 2 * (A+B)/(A*B)
A * B = 4

Hence if A * B < 4, S_T < S_T. Otherwise, S_T > S_R.


q = s * d

q = flow rate of vehicles per hour
s = average vehicle per hour
d = density, measured in vehicle per mile

Spacing per foot is calculated by: (5280 ft/mi)

d_ a = 5280/d

Where vehicle headway is calculated by: (3600 sec/hr)

h_a = 3600/q

Example: Observing a part of a highway for one hour, an engineer observes 890 vehicles pass at an average of 55.5 miles per hour in one direction.

The density is: d = 890/55.5 ≈ 16.0360 vehicles per mile

This leads to a spacing per foot as: d_a ≈ 5280/16.0360 ≈ 329.2584 feet per vehicle

And the headway per vehicle is: h_ a = 3600/890 ≈ 4.0449 seconds per vehicle

There are several models regarding traffic flow and density. One is the Greenfield's Linear Model, a general model that is used in most traffic conditions.

S_R = S_ f * (1 - D/D_j)

S_R = average space mean speed (harmonic average of speeds)

S_f = free flow speed. This is the speed one would travel if there was no traffic, the weather was near perfect, and there are no obvious road obstacles.

D = actual density

D_j = jam density. The jam density is achieved when traffic is stopped. If you live in the Greater Los Angeles area, you can easily observe freeways at jam density. And yes, it is a pain to drive on the I-210 Parking Lot.

There are other models that the boom describes, such as the Greenberg Density model, which is used for dense traffic situations only.

The Space Mean Speed of a Train

The book provides a very interesting example of using simple velocity and acceleration equations from physics to help calculate S_R. Here is an example (not from the book, but one I made up):

A train, the Star Train, travels from Mario Station to Luigi Station, which is a 14 mile (73920 ft) trip. The train takes one minute to load and drop passengers at each station. Information for the Star Train is as follows:

Acceleration: 5 ft/s^2
Deceleration: 4.5 ft/s^2
Peak Speed: 84 mph ≈ 123.48 ft/s

What is the space mean speed?

We have the first find out the total time, including delays.

Accelerating phase:
Time it takes to accelerate to full speed: t _a = v_f/a = 123.48/5 ≈ 24.696 s
Distance traveled: s_a = a*t_a^2/2 = 5 * 24.696^2 / 2 ≈ 1524.731 ft

Deceleration phase:
Time it takes to decelerate from full speed: t_d = -v_f/-a_d = -123.48/-4.5 ≈ 27.44 s
Distance traveled:
s_d = -a_d*t_d^2/2 + t*v_f = -4.5*27.44^2/2 + 27.44*123.48 ≈ 1694.1456 ft

Constant Speed Phase:
Here we reverse the order of calculations: distance, the time.
s_c = L - s_a - s_d = 73920 - 1524.731 - 1694.1456 = 70701.123
t_c = s_c/v_f = 70701.123/123.48 ≈ 572.5715 ft/s

Total time:
T = t_a + t_c + t_d + t_delays
= 24.696 + 572.5715 + 27.44 + 60 * 2
= 744.7075 s (about 12 min 24 s)

Finally calculate space mean speed:
S_R = L/T = 73920/744.7075 ≈ 99.2604 ft/s ≈ 67.5241 mph

So the space mean speed of the Star Train from Mario Station to Luigi Station is about 67.5241 miles and hour.

(1 mi/hr ≈ 1.47 ft/s, actually 1.4666666666666... ft/s = 22/15 ft/s)

Hopefully this helps and you enjoyed this post as I did. As always comments and questions are welcome and appreciated. Until next time, take care!


This blog is property of Edward Shore. 2014

Three Generations of the BA II Plus

Here is my collection of the BA II Plus calculators I have with the year I bought them typed into each one.


Tuesday, April 1, 2014

HP 15C: Pythagorean Triples

HP 15C:   Pythagorean Triples This program calculates the Pythagorean triple (A, B, C) such that A^2 + B^2 = C^2 by the formulas: ...