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

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.

TI 30Xa Algorithm: Acceleration, Velocity, Speed

TI 30Xa Algorithm: Acceleration, Velocity, Speed Introduction and Algorithm Given the acceleration (α), initial velocity (v0), and...