Showing posts with label Fun With Num3ers. Show all posts
Showing posts with label Fun With Num3ers. Show all posts

Sunday, April 19, 2015

HP Prime: Sums and Differences of Triangular Numbers, Triangular Numbers functions

HP Prime:  Sums and Differences of Triangular Numbers, Triangular Numbers functions

  


Benjamin Vitale, author of the Fun With Numb3rs blog (https://benvitalenum3ers.wordpress.com) wrote:

Consider the following system of equations:

T_a + T_b = T_c
T_a – T_b = T_d

Where T represents triangular numbers, which is defined by:

T_n = n * (n+1)/2 where n is a positive integer

(Retrieved April 16, 2015)

Then:
T_a + T_b = T_c
T_a – T_b = T_d

Let:
a*(a+1)/2 + b*(b+1)/2 = C
a*(a+1)/2 – b*(b+1)/2 = D

C and D need to be tested to determine if they are both triangular numbers, which is fairly easy to check.  Without loss of generality, let:

C = n*(n+1)/2
2*C = n*(n+1)
2*C = n^2 + n
0 = n^2 + n – 2*C

Solving for n:

n = (-1 ± √(1^2 – 4*-1*2*C))/2

Since we are looking integers where n>0, we can state that:

n = (-1 + √(1^2 – 4*-1*2*C))/2
n = (-1 + √(1 – 8*C))/2
n = -.5 + √((1 – 8*C)/4)
n = -.5 + √(.25 – 2*C)

If frac(n) = 0, we have a solution.   (frac stands the fraction function)

The program TRIINTEST will list pairs of triangular numbers.  The argument of TRIINTEST(n), where n is upper limit of T_n to be tested.
HP Prime Program:  TRIINTEST

EXPORT TRIINTTEST(u)
BEGIN
// 2014-04-18
LOCAL a,b,c,d;
LOCAL A,B,C,D;
// matrix starter
LOCAL m:=[[0,0]];
LOCAL s:=2;
FOR a FROM 2 TO u DO
FOR b FROM 1 TO a DO
A:=(a^2+a)/2;
B:=(b^2+b)/2;
C:=A+B;
D:=A-B;
c:=−.5+√(.25+2*C);
d:=−.5+√(.25+2*D);

IF FP(c)==0 AND FP(d)==0 THEN
ADDROW(m,[A,B],s);
s:=s+1;
END;

END;
END;

// clean up
DELROW(m,1);
RETURN m;
END;


Finding pairs from T_1 to T_50:

[[ 3, 3 ]
[ 21, 15 ]
[ 105, 105 ]
[ 171, 105 ]
[ 703, 378 ]
[ 990, 780 ]]


Here are the functions TRINUM and ITRINUM:

TRINUM(n):  returns the nth triangular number. 

ITRINUM(t):  test whether t is a triangular number.  If t is not a triangular number, -1 is returned.
Program TRINUM:

EXPORT TRINUM(N)
BEGIN
// triangular number
RETURN N*(N+1)/2;
END;


Program ITRINUM:

EXPORT ITRINUM(T)
BEGIN
// inverse triangular number
// returns −1 if not a triangular
// number
LOCAL t:=(−.5+√(.25+2*T));
IF FP(t)==0 THEN
RETURN t;
ELSE
RETURN −1;
END;
END;

Examples:

TRINUM(15) = 120  (15th triangular number)

ITRINUM(276) = 23   (276 is the 23rd triangular number)
ITRINUM(572) returns -1   (572 is not a triangular number)


This blog is property of Edward Shore.  2015

Sunday, December 16, 2012

Adding Numbers and their Reverses



Please take a look at the Fun With Num3ers blog by Benjamin Vitale (Twitter: @BenVitale). This is a fun blog working with number theory. It is also an inspiration for me to blog. Thanks, Ben!

Eddie

Link: http://benvitalenum3ers.wordpress.com/


On to today's blog entry!

Two Digit Numbers

Let AB represent a two digit number, where A and B each represent a digit 0 through 9 (excluding 00). My original goal was to find a number AB such that AB + BA = n where n contains both digits A and B. I was unsuccessful.

However, I did see something curious:

11 + 11 = 22
12 + 21 = 33
13 + 31 = 44
14 + 41 = 55
15 + 51 = 66
16 + 61 = 77
17 + 71 = 88
18 + 81 = 99
19 + 91 = 110
10 + 01 = 10 + 1 = 11

All the sums for this group are multiples of 11.

If I go on...
21 + 12 = 33
22 + 22 = 44
23 + 32 = 55
24 + 42 = 66
25 + 52 = 77
....

Once again, multiples of 11. Can we show that this is true for all sums AB + BA?

Let a represent the digit A. Similarly, let b represent the digit B. Then:

AB = (10a + b) and BA = (10b + a)

Then the sum AB + BA = (10a + b) + (10b + a) = 11a + 11b = 11(a + b)

Three Digit Numbers

Let's consider the number ABC. Rotate ABC one digit and add. Repeat. We get the sum ABC + BCA + CAB = n.

Let a, b, and c represent the digits A, B, and C, respectively. Then ABC = 100a + 10b + c. We can construct two similar sums for BCA and CAB.

Then

ABC + BCA + CAB
= (100a + 10b + c) + (100b + 10c + a) + (100c + 10a + b)
= 111a + 111b + 111c
= 111(a + b + c)

The sum is ends up a multiple of 111, but not necessarily of 11. (111 is not a multiple of 11). Examples?

Example 1:
425 + 254 + 542 = 1221
1221/111 = 11
1221/11 = 111

Example 2:
963 + 639 + 396 = 1998
1998/111 = 18
1998/11 = 181 6/11
1998 is not a multiple of 11

Can we find such triples ABC, BCA, and CAB such that the sum is divisible by both 11 and 111? Hint: the least common multiple of 11 and 111 is 1,221. I have found 31 such triplets (including the trivial 0,0,0).

If you want to find the triples, have fun! I'll leave you with a few examples:

29 + 902 + 290 = 1221. (029, 902, 290)
137 + 713 + 371 = 1221. (137, 713, 371)
598 + 859 + 985 = 2442. (598, 859, 985)
254 + 425 + 542 = 1221. (254, 425, 542)

Take care and be safe!

Eddie


This blog is property of Edward Shore. 2012

Python (TI-84 Evo) and HP 32S: Shannon-Wiener Diversity Index

Python (TI-84 Evo) and HP 32S: Shannon-Wiener Diversity Index Introduction The Shannon-Wiener Diversity Index measures a leve...