Showing posts with label calendar. Show all posts
Showing posts with label calendar. Show all posts

Saturday, April 17, 2021

Fun with the HP 20S (April 17, 2021 Edition)

Fun with the HP 20S (April 17, 2021 Edition)


A Quick Note - Spam Comments 

I noticed that my blog recently had a lot spam comments, especially since the beginning of this year.  Because of this I am considering turning off the ability to leave comments altogether.  If you are going to comment, please be courteous and stay on topic.  No one wants to read the same spam post about off-shore casinos, printers, or scandalous divorce inquiries.

Thank you and now, on with the post.  



Integer Division


The program calculates the quotient and remainder of the division: 


a ÷ b


Instructions:


Enter a, press [ XEQ ] ( F ), enter b.   Get the quotient, press [ R/S ], get the remainder



Program:


01 61,41,F         LBL F

02 21,2 STO 2

03 45        ÷

04 26        R/S

05 21, 1    STO 1

06 74          =

07 21,0      STO 1

08 51,45    IP

09 26          R/S

10 22,0      STO 0

11 61,45    FP

12 55        ×

13 22,1      RCL 1

14 74        =

15 51,33,0         FIX 0

16 61,44    RND   (round)

17 61,34    ALL

18 61,26    RTN



FIX 0, RND, ALL:  round the number in the display to the nearest integer


Examples:


74 ÷ 6  = 12 R 2

Keystrokes:  74, XEQ F, 6, R/S (12) R/S (2)


1576 ÷ 237 = 6 R154


Day Number


This calculates the day number given the month and the date.   A 365-day year is assumed.  


Instructions:

1.  Store month in memory register 1

2.  Store day in memory register 2

3.  Press XEQ A


Program:


01 61,41,A         LBL A

02 22,1      RCL 1

03 31        INPUT

04 2          2

05 61,42    x≤y?

06 51,41,1         GTO 1

07 33          (

08 33        (

09 22,1      RCL 1

10 75        +

11 1          1

12 34          )

13 55        ×

14 3            3

15 0          0

16 73        .

17 6          6

18 34          )

19 51,45    IP

20 65        -

21 6            6

22 3          3

23 74          =

24 21,3      STO 3

25 51,41,2         GTO 2

26 61,41,1         LBL 1

27 33          (

28 33        (

29 22,1      RCL 1

30 65        -

31 1          1

32 34      )

33 55        ×

34 6            6

35 3          3

36 45        ÷

37 2          2

38 34        )

39 51,45    IP

40 74        =

41 21,3      STO 3

42 61,41,2         LBL 2

43 75        +

44 22,2      RCL 2

45 74        =

46 21,3      STO 3

47 61,26    RTN


Examples:


February 16:  2 STO 1, 16 STO 2, XEQ A.  Result:  47

August 22:  8 STO 1, 22 STO 2, XEQ A.   Result:  234


Source:

Duffett-Smith, Peter.  Practical Astronomy With Your Calculator  2nd Ed.  Cambridge University Press: Cambridge.  1979  ISBN 0-521-28411-2


Astronomy:  Geocentric Parallax


The program calculates the quantities ρ sin θ' and ρ cos θ' where:


ρ = distance the observer is from the center of the Earth in meters

θ' = geocentric latitude in degrees


Inputs:


h = height of observer above sea level in meters

L = latitude of the observer in degrees, north is positive


Calculations:


h' = h / 6378140   (estimated radius of Earth is about 6,378 km)

u = atan(0.996647 tan L)

ρ sin θ' = 0.996647 sin u + h' sin L

ρ cos θ' = cos u + h' cos L


Program:


01 61,41,b         LBL B

02 61,23    DEG

03 33          (

04 22,1      RCL 1

05 25        TAN

06 55        ×

07 73        .

08 9          9

09 9          9

10 6            6

11 6          6

12 4          4

13 7          7

14 21,0      STO 0

15 34          )

16 51,25    ATAN

17 21,3      STO 3

18 22,2      RCL 2

19 45        ÷

20 6            6

21 3            3

22 7            7

23 8          8

24 1            1

25 4          4

26 0          0

27 74          =

28 21,4        STO 4

29 22,0      RCL 0

30 55          ×

31 22,3      RCL 1

32 23        SIN

33 75        +

34 21,1      RCL 1

35 23          SIN

36 55            ×

37 22, 4        RCL 4

38 74        =

39 26          R/S

40 22, 3        RCL 3

41 24            COS

42 75          +

43 22, 4      RCL 4

44 55        ×

45 22, 1      RCL 1

46 24          COS

47 74          =

48 61,26      RTN


Registers used:


R1 = L  (input)

R2 = h   (input)

R3 = u

R4 = h / 6378140

R0 = 0.996647


Example:


Input:

L = 45.76° N

h = 53.48 m


54.76 STO 1, 53.48 STO 2, XEQ B

Result:  

ρ sin θ' = .712859241, R/S

ρ cos θ' = .698873028


Source:

Duffett-Smith, Peter.  Practical Astronomy With Your Calculator  2nd Ed.  Cambridge University Press: Cambridge.  1979  ISBN 0-521-28411-2


Eddie

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

Thursday, October 10, 2019

HP 41C/DM 41: Halloween and Thanksgiving - Calendar Calculations

HP 41C/DM 41:  Halloween and Thanksgiving - Calendar Calculations

Introduction 



We are about to enter the annual holiday season, and it's can be hard to remember when all the holidays.  Here is a way to determine what date Thanksgiving will be on this year, and all you have to know is what day of the week Halloween falls on.

Halloween is celebrated on October 31.  Halloween is celebrated on a fixed date, while Thanksgiving is celebrated on a fixed day of the week.

In the United States, Thanksgiving is on the fourth Thursday in November.  Therefore the only dates Thanksgiving in the United States is between November 22 and November 28.

In Canada, Thanksgiving is on the second Monday in October, which lands the possible dates between October 8 and October 14. 

Determine The Date of Thanksgiving Knowing What Day of the Week Halloween Is On

The first step is to give each day a numeric value:

Sunday: 0
Monday:  1
Tuesday:  2
Wednesday:  3
Thursday:  4
Friday:  5
Saturday:  6

To determine what date Thanksgiving falls on in the United States:

1.  Let H be the numeric value for the day Halloween falls on (see the above chart). 
2.  Subtract 4 from H.
3.  If the result is zero or negative, add 28; otherwise, add 21. 

Note:  The following programs could address alternative approaches given what the command set of the HP 41C/DM 41 allows us to do. 

HP 41C/DM 41 Program:  H>T

01 LBL^T  H>T
02 4
03 X<>Y
04 -
05 X>0?
06 GTO 01
07 7
08 +
09 LBL 01
10 21
11 + 
12 RTN

To determine what date Thanksgiving falls on in Canada:

1.  Let H be the numeric value for the day Halloween falls on (see the above chart). 
2.  Subtract H from 7. 
3.  Subtract 3 from the last result.
4.  If the result from Step 3 is zero or negative, add 14; otherwise, add 7.

HP 41C/DM 41 Program: H>CT

01 LBL^T H>CT
02 7
03 X<>Y
04 -
05 3
06 -
07 X>0?
08 GTO 01
09 7
10 +
11 LBL 01
12 7
13 + 
14 RTN

Now, let's go the other way.

Determine The Day of the Week Halloween Knowing the Date of Thanksgiving

The first step is to give each day a numeric value:

Sunday: 0
Monday:  1
Tuesday:  2
Wednesday:  3
Thursday:  4
Friday:  5
Saturday:  6

To determine the day of the week Halloween falls on given the date of Thanksgiving (United States):

1.  Let T be the date of Thanksgiving.
2.  Subtract 21 from T. 
3.  Subtract the result from Step 2 from 4.  If the number is negative, add 7.  See the above chart to determine the Day of the Week.

HP 41C/DM41 Program:  T>H

01  LBL^T T>H
02 21
03 - 
04 4
05 X<>Y
06 -
07 X<0 font="">
08 GTO 01
09 RTN
10 LBL 01
11 7
12 + 
13 RTN

To determine the day of the week Halloween falls on given the date of Thanksgiving (Canada):

1.  Let T be the date of Thanksgiving.
2.  Subtract T from 11.  If the result is negative, add 7.  See the above chart to determine the Day of the Week.

HP 41C/DM41 Program:  CT>H

01 LBL^T CT>H
02 11
03 X<>Y
04 -
05 X<0 font="">
06 GTO 01
07 RTN
08 LBL 01
09 7
10 +
11 RTN

Are you ready for the holiday season?  I'm not sure I am.  Let's have fun,

Eddie

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

HP Prime, TI-84 Plus, and Casio fx-CG 50: Julian Date/Gregorian Calendar Conversions

HP Prime, TI-84 Plus, and Casio fx-CG 50:  Julian Date/Gregorian Calendar Conversions

Introduction

One conversion that is common in astronomy is to convert dates from our Gregorian calendar (the most commonly used day-to-day calendar) to a Julian Date Number, and visa versa.

JD:  Convert Gregorian Date to Julian Date Number

GREG:  Convert Julian Date Number to Gregorian Date

The Julian date number of 2451545 corresponds to January 1, 2000.

Gregorian Date to Julian Date Number

HP Prime Program JD:  Gregorian Date to Julian Date Number
Arguments:  four digit year, month, day
JD(y,m,d)

EXPORT JD(y,m,d)
BEGIN
// Gregorian to Julian
// year, month, day
// 2019-01-12 EWS
//  Wikipedia
LOCAL x0:=IP((m-14)/12);
LOCAL x1:=IP(((1461*(y+4800+x0))/4));
LOCAL x3:=IP(367*(m-2-12*x0)/12);
LOCAL x5:=IP((y+4900+x0)/100);
LOCAL x6:=IP(3*x5/4);
LOCAL j:=x1+x3-x6+d-32075;
RETURN j;
END;

TI-84 Plus Program JD:  Gregorian Date to Julian Date Number

"GREGORIAN TO JULIAN"
"2019-01-13 EWS"
Input "YEAR: ",Y
Input "MONTH: ",M
Input "DAY: ",D
iPart((M-14)/12)→X
iPart(((1461*(Y+4800+X))/4))→A
iPart(367*(M-2-12*X)/12)→B
iPart((Y+4900+X)/100)→C
iPart(3*C/4)→C
A+B-C+D-32075→J
Disp "JD: ",J

Casio fx-CG50 Program JD:  Gregorian Date to Julian Date Number
This version can be typed in directly in the calculator (not a text file)

"GREGORIAN TO JULIAN"
"2019-01-19 EWS"
"YEAR?"→Y
"MONTH"?→M
"DAY"?→D
Int ((M-14)÷12)→X
Int (((1461×(Y+4800+X))÷4)) →A
Int (367×(M-2-12×X)÷12) →B
Int ((Y+4900+X) ÷ 100) →C
Int (3×C÷4)→C
A+B-C+D-32075→J
ClrText
Locate 1,1,"JD"
Locate 1,2,J

Julian Date Number to Gregorian Date

HP Prime Program GREG:  Julian Date Number to Gregorian Date
Argument:  Julian Date Number
GREG(j)

EXPORT GREG(j)
BEGIN
// Julian to Gregorian
// Wikipedia
// 2019-01-12 EWS
LOCAL x1:=IP((4*j+274277)/146097);
LOCAL x2:=IP(x1*3/4);
LOCAL f:=j+1401+x2-38;
LOCAL E:=4*f+3;
LOCAL G:=IP((E MOD 1461)/4);
LOCAL H:=5*G+2;
LOCAL D:=IP((H MOD 153)/5)+1;
LOCAL M:=((IP(H/153)+2) MOD 12)+1;
LOCAL Y:=IP(E/1461)-4716+IP((12+2-M)/12);
RETURN {Y,M,D};
END;

TI-84 Plus Program GREG:  Julian Date Number to Gregorian Date

"JULIAN TO GREGORIAN"
"2019-01-13 EWS"
Input "JD: ",J
iPart((4*J+274277)/146097)→X
iPart(X*3/4)→X
4*(J+1401+X-38)+3→E
5*iPart(remainder(E,1461)/4)+2→H
iPart(remainder(H,153)/5)+1→D
remainder(iPart(H/153)+2,12)+1→M
iPart(E/1461)-4716+iPart((12+2-M)/12)→Y
Disp "YEAR, MONTH, DAY:",Y,M,D

Casio fx-CG50 Program GREG: Julian Date Number to Gregorian Date 
This version can be typed in directly in the calculator (not a text file)

"JULIAN TO GREGORIAN"
"2019-01-13 EWS"
"JD"?→J
Int ((4 ×J+274277) ÷146097) →X
Int (X ×3 ÷4) →X
4 ×(J+1401+X-38)+3 → E
5 × Int( MOD(E,1461) ÷ 4)+2 → H
MOD(Int  (H ÷153)+2,12)+1 →M
Int (E ÷1461) -4716+Int ((12+2-M) ÷12) → Y
ClrText
Locate 1,1,"YEAR, MONTH, DAY"
Locate 1,2,Y
Locate 1,3,M
Locate 1,4,D

Examples

Gregorian Date:  1988, October 31
JD:  2447466

Gregorian Date:  1999, January 11
JD:  2451190

Gregorian Date:  2017, March 21
JD:  2457834


Source:

"Julian Day"  Wikipedia.  Edited (when retrieved) November 19, 2018.  Retrieved January 11, 2019.  https://en.wikipedia.org/wiki/Julian_day

Eddie

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

Thursday, October 12, 2017

HP Prime and Casio fx-CG 50: Leap Year Test

HP Prime and Casio fx-CG 50: Leap Year Test

Introduction

The presented program tests whether a year is a leap year.  A leap year has 366 days instead of 365, with the extra day given to February (February 29).  The criteria for a leap year are:

* Leap years are year numbers evenly divisible by 4.  Example:  1992, 2016
* Exception:  years that are divisible by 100 but not divisible by 400.  Example:  2000 is a leap year, but 1900 and 2100 aren’t.

HP Prime Program ISLEAPYEAR

EXPORT ISLEAPYEAR(y)
BEGIN
IF FP(y/4) ≠ 0 OR (FP(y/100) == 0 AND FP(y/400) ≠ 0)
THEN
RETURN 0;
ELSE
RETURN 1;
END;
END;


Casio fx-CG 50 ISLEAPYR

“YEAR”? → Y
If Frac(Y ÷ 4) ≠ 0 Or (Frac(Y ÷ 100) = 0 And Frac(Y ÷ 400) ≠ 0)
Then
“No” ◢
Else
“YES” ◢
IfEnd

Eddie


This blog is property of Edward Shore, 2017.

Sunday, September 4, 2016

HP 12C Platinum: Finding the Day of Easter

HP 12C Platinum:  Finding the Day of Easter

An Easter Algorithm

One can figure out when Easter is by the following algorithm:

“  c = y / 100

    n = y - 19 * ( y / 19 )

    k = ( c - 17 ) / 25

    i = c - c / 4 - ( c - k ) / 3 + 19 * n + 15

    i = i - 30 * ( i / 30 )

    i = i - ( i / 28 ) * ( 1 - ( i / 28 ) * ( 29 / ( i + 1 ) )

        * ( ( 21 - n ) / 11 ) )

    j = y + y / 4 + i + 2 - c + c / 4

    j = j - 7 * ( j / 7 )

    l = i - j

    m = 3 + ( l + 40 ) / 44

    d = l + 28 - 31 * ( m / 4 )
“  (see the Source below, http://aa.usno.navy.mil/faq/docs/easter.php )

The only input is y, the four digit year (1997, 2015, etc).   Each of the slashes “/” in the above text refers to integer division.  Hence in this case:  a/b refers to INTG(a ÷ b).

Other things I noticed while porting this algorithm to the HP 12C Platinum:

The line y - 19 * ( y / 19 ) can be expressed as y MOD 19 and 19 * fPart(y ÷ 19).   This happens in three other lines (2nd, 5th, and 8th).  See how to calculate the MOD function, when both arguments are positive on the HP 12C here:  http://edspi31415.blogspot.com/2016/07/hp-12c-programming-part-i-modulus-gcd.html

On the HP 12C Platinum, the LSTx function moved to [ g ] [ + ].  (Code 43, 40)

After the 5th line, the variable i will between 0 and 29.  If i ≤ 27, the 6th line can be skipped entirely since iPart(i/28) = 0.  Otherwise, iPart(i/28) = 1.  This cuts on down the number of steps needed.

I was also to combine some steps in the beginning by computing c and k while building i at the same time.

Storage arithmetic is allowed on R0 – R4 on both the HP 12C Platinum and the classic HP 12C.  By the way, the reason why I mention the HP 12C Platinum is that this program is 133 steps.  Only 99 steps are possible on the classic HP 12C.

Store registers:
R0: four digit year
R1:  c, m (result: month)
R2:  n, j, d (result: day)
R3: k, l
R4: i

Instructions:  Enter the four digit year.  Press [ R/S ].  The month will be displayed (stored in R1).  Press [ R/S ] to get the day (stored in R2).

HP12C Platinum Program:  Easter

STEP
CODE
KEY
Notes
001
44, 0 
STO 0
Store year (y)
002
1
1

003
25
%

004
43, 25
INTG

005
44, 1
STO 1
Store c
006
44, 4
STO 4
Start i
007
 36
ENTER
To fill the stack
008
36
ENTER

009
4
4

010
10
÷

011
43, 25
INTG

012
44, 30, 4
STO- 4

013
33
R↓

014
36
ENTER

015
36
ENTER

016
1
1

017
7
7

018
30
-

019
2
2

020
5
5

021
10
÷

022
43, 25
INTG

023
44, 3
STO 3
Store k
024
30
-

025
3
3

026
10
÷

027
43, 25
INTG

028
44, 30, 4
STO- 4

029
1
1

030
5
5

031
44, 40, 4
STO+ 4

032
45, 0
RCL 0

033
1
1

034
9
9

035
10
÷

036
43, 40
LSTx
LSTx is [ g ] [ + ] on the Platinum
037
34
X<>Y

038
43, 24
FRAC

039
20
*
 y MOD 19
040
44, 2
STO 2
 Store n
041
1
1

042
9
9

043
20
*

044
44, 40, 4
STO+ 4

045
45, 4
RCL 4

046
3
3

047
0
0

048
10
÷

049
43, 40
LSTx

050
34
X<>Y

051
43, 24
FRAC

052
20
*

053
44, 4
STO 4
i MOD 30
054
2 
2

055
7
7

056
45, 4
RCL 4

057
43, 44
x≤y
Is i≤27?
058
43, 33, 080
GTO 080
If so, go to step 080
059
2
2

060
9
9

061
45, 4
RCL 4

062
1
1

063
40
+

064
10
÷

065
43, 25
INTG

066
20
*

067
1
1

068
34
X<>Y

069
30
-

070
2
2

071
1
1

072
45, 2
RCL 2

073
30
-

074
1
1

075
1
1

076
10
÷

077
43, 25
INTG

078
20
*

079
44, 30, 4
STO- 4

080
45, 0 
RCL 0

081
45, 2
STO 2
Start j
082
4
4

083
10
÷

084
43, 25
INTG

085
 44, 40, 2
STO+ 2

086
45, 4
RCL 4

087
2
2

088
40
+

089
45, 1
RCL 1

090
30
-

091
44, 40, 2
STO+ 2

092
45, 1
RCL 1

093
4
4

094
10
÷

095
43, 25
INTG

096
44, 40, 2
STO+ 2

097
45, 2
RCL 2

098
7
7

099
10
÷

100
43, 40
LSTx

101
34
X<>Y

102
43, 24
FRAC

103
20
*

104
44, 2
STO 2
j MOD 7
105
 45, 4
RCL 4

106
34
X<>Y

107
30
-

108
44, 3
STO 3
Store l
109
4
4

110
0
0

111
40
+

112
4
4

113
4
4

114
10
÷

115
43, 25
INTG

116
3
3

117
40
+

118
44, 1
STO 1
Store month (m)
119
31
R/S
Displays m
120
4
4

121
10
÷

122
43, 25
INTG

123
3
3

124
1
 1

125
20
*

126
16
CHS

127
2
2

128
8
8

129
40
+

130
45, 3
RCL 3

131
40
+

132
44 , 2
STO 2
Store day (d)
133
43, 33, 000
GTO 000
Stop, display d


Examples and Test Data:

2016: 3, 27
Keystrokes:  2016 [R/S] [R/S]

1995: 4, 16
2124: 4, 2
1977: 4, 10
2017: 4, 16
1826: 3, 26

These results have been verified. 

Now we can determine when is Easter at any year.  Happy Easter in advance!

Eddie

Source:    The United States Naval Observatory  “The Date of Easter”  March 11, 2016.  http://aa.usno.navy.mil/faq/docs/easter.php  Retrieved September 2, 2016



This blog is property of Edward Shore, 2016.

Python: Drawing a Ring of Circles

Python: Drawing a Ring of Circles The goal: Draw a number of circles that revolve around the origin (0,0). The center of each circle i...