## 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.

1. This comment has been removed by the author.

2. There are two years to test. For the year 1943: April 25th. For the year 1954: April 18th. The latest possible Easter date is April 25th. For the year 1954 a correction is required to prevent that Easter isn't celebrated on the 25th

1. Tests: 1943: 4, 25. 1954: 4, 18. So far so good.

2. This comment has been removed by the author.

3. I auditioned for the year 1970 and unfortunately got the wrong date of Easter and also in 2122 for error! The two years are reported for March 22.

4. In 1970 and 2122 Easter is celebrated on March 29. There seems to be an error in one of the corrections. Here is the program I've developed for HP-38G:

INPUT Y;
“When is Easter?”;
“Year”;
“1582 < Gregorian year < 10000”;
1+1E4*FRAC(1E2*DATE):
1+(Y MOD 19) A: ▶
1+INT(Y/100) B: ▶
INT((3*B)/4)­12 C: ▶
INT((8*B+5)/25)­5 D: ▶
INT((5*Y)/4)­10­C E: ▶
(((11*A+20+D­C) MOD 30)+30) MOD 30 F: ▶
IF (F == 24) OR ((F == 25) AND (A > 11)) THEN
F+1 F: ▶
END:
44­F G: ▶
IF G < 21 THEN
30+G G: ▶
END:
7+G­((E+G) MOD 7) H: ▶
ERASE:
IF H > 31 THEN
MSGBOX “Easter is on April “ H­31 “, ” Y:
ELSE
MSGBOX “Easter is on March “ H “, “ Y:
END:
STOP:

5. I've check the algorithm and for 1970 it calculates March 29. So there must be something else amiss.

6. 01 INTG
02 STO 1
03 STO 0
04 1
05 9
06 /
07 INTG
08 1
09 9
10 *
11 STO-0
12 RCL 0
13 1
14 1
15 STO*0
16 /
17 STO 2
18 4
19 4
20 STO+0
21 1
22 RCL 1
23 %
24 INTG
25 +
26 3
27 2
28 %
29 .
30 2
31 +
32 INTG
33 STO+0
34 R↓
35 7
36 5
37 %
38 INTG
39 STO 3
40 STO-0
41 RCL 0
42 3
43 0
44 /
45 INTG
46 3
47 0
48 *
49 STO-0
50 RCL 2
51 RCL 0
52 x<=y?
53 GTO 55
54 GTO 57
55 1
56 +
57 STO 4
58 CHS
59 RCL 1
60 .
61 8
62 /
63 INTG
64 +
65 RCL 3
66 -
67 3
68 +
69 STO 0
70 7
71 /
72 INTG
73 7
74 *
75 RCL 0
76 -
77 RCL 4
78 -
79 5
80 4
81 +
82 RCL 1
83 EEX
84 6
85 /
86 3
87 .
88 0
89 3
90 +
91 X<>Y
92 DATE
93 FIX 6
94 GTO 00

Follows up the solution!

Thank you so much, but I found a solution to the 12c!

Here is a 12C version of this algorithm. It does not require any subroutine calls and takes advantage of the DATE function which allows the code to fit in 94 lines. This way even the date format setting is observed (MM.DDYYYY or DD.MMYYYY)

### TI-84 Plus CE: Storing Names in a Concentrated String

TI-84 Plus CE: Storing Names in a Concentrated String  Introduction The program STRNAMES allows the user to store a list of names in a ...