(41CX/DM41)(17Bii) Date of the first Advent Sunday in a year
02-04-2020, 10:34 PM (This post was last modified: 02-04-2020 10:35 PM by jthole.)
Post: #1
 jthole Member Posts: 60 Joined: Nov 2017
(41CX/DM41)(17Bii) Date of the first Advent Sunday in a year
This small program is an adaptation of an equation I have in my HP 17Bii. One of the reasons for posting this here, is that it shows the elegance of the HP 17Bii solver. The other reason is that it's fun, and can be useful (if only because you know when to open the first window of the Advent calendar ;-) ).

First of all, here is the short and simple HP 17Bii Solver equation: (both the solver and program assume DD.MMYYYY).
Code:
 ADVDATE = DATE( L( XMAS : YEAR ÷ 1000000 + 25.12 ) : ( ( MOD( DDAYS( 1.0119 : G( XMAS ) : 1 ) : 7 ) + 22 ) x - 1 ) )

And here is the HP 41CX/DM41L program, which takes the year in the X register (just following the equation; maybe could be optimised further).
Code:
 LBL "ADVDATE" 1000000 / 25.12 + STO 00 1.0119 X<>Y DDAYS  ;XROM 26,14 7 MOD 22 + CHS RCL 00 X<>Y DATE+  ;XROM 26,13 END

Running on the 17Bii:
Enter YEAR: 2021

Running on the DM41L:
2021
28,112021

Of course, the program (and equation) only works for the Gregorian calendar. Monday Jan. 1, 1900 was chosen because I liked that date (any date works, as long as you adjust the offset (currently 22) in the equation.

BTW; I do not have a HP 41CX, but I do have a SwissMicros DM41L; I tested the program on the DM41L.
08-10-2020, 03:02 PM (This post was last modified: 08-10-2020 03:11 PM by ggauny@live.fr.)
Post: #2
 ggauny@live.fr Senior Member Posts: 566 Joined: Nov 2014
RE: (41CX/DM41)(17Bii) Date of the first Advent Sunday in a year
Hi,

I see your thread a little late but here is a little routine of mine I was using with my
HP 41c (+ time module) or my HP 41cx.

Instead of DDays I'm using DOW, but unfortunatly DOW gives 0 if the day is a sunday, (HP Prime gives 7). So we have to "adjust" in case of DOW gives a 0.

Code:
 01 LBL "DIMAVENT' 02 7                        //Here is the adjust. 03 x<>y 04 1e6 05 / 06 25.12 07 + 08 ENTER 09 DOW 10 x=0? 11 x<> Z                 // or RCL+ ST Z on HP 42s, FREE42, DM42 12 21 13 + 14 CHS 15 DATE+ 16 END

Of course runing on dm41, dm41x too and some other calculator.

2016 gives 27.112016 for example, 1582 gives 28.111582

In attachement I give 2 EXCEL calendars. May be usefull.

Have a good day.

Attached File(s)

Gérard.
08-11-2020, 08:03 AM (This post was last modified: 08-11-2020 02:29 PM by Werner.)
Post: #3
 Werner Senior Member Posts: 725 Joined: Dec 2013
RE: (41CX/DM41)(17Bii) Date of the first Advent Sunday in a year
If you use 12.12 instead of 25.12, and change the 21 to 8, it will work for M.DY format as well.
[update] not quite.. but if you use 12.12, then do 13 DAYS+, then proceed as before, it will ;-)
[update #2] and if you take the first of January of the next year (which is always the same Day of Week as Christmas), it's even simpler:
Code:
 1  +  1E6  /  1.01  +  ENTER  DOW  +/-  7  MOD  35  -  DATE+
Cheers, Werner
01-22-2021, 01:27 PM
Post: #4
 Wolfgang Member Posts: 53 Joined: Jun 2014
RE: (41CX/DM41)(17Bii) Date of the first Advent Sunday in a year
(08-10-2020 03:02 PM)ggauny@live.fr Wrote:  Hi,

I see your thread a little late but here is a little routine of mine I was using with my
HP 41c (+ time module) or my HP 41cx.

Instead of DDays I'm using DOW, but unfortunatly DOW gives 0 if the day is a sunday, (HP Prime gives 7). So we have to "adjust" in case of DOW gives a 0.

Code:
 01 LBL "DIMAVENT' 02 7                        //Here is the adjust. 03 x<>y 04 1e6 05 / 06 25.12 07 + 08 ENTER 09 DOW 10 x=0? 11 x<> Z                 // or RCL+ ST Z on HP 42s, FREE42, DM42 12 21 13 + 14 CHS 15 DATE+ 16 END

Of course runing on dm41, dm41x too and some other calculator.

2016 gives 27.112016 for example, 1582 gives 28.111582

For HP Prime:

SHIFT Define <function> for user defined function

HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more
01-24-2021, 05:00 AM
Post: #5
 Albert Chan Senior Member Posts: 1,998 Joined: Jul 2018
RE: (41CX/DM41)(17Bii) Date of the first Advent Sunday in a year
(08-10-2020 03:02 PM)ggauny@live.fr Wrote:  Instead of DDays I'm using DOW, but unfortunatly DOW gives 0 if the day is a sunday, (HP Prime gives 7).
So we have to "adjust" in case of DOW gives a 0.

No need to adjust, just shift the reference to Christmas Eve.
Better yet, reference to Dec 3, eliminated the need to subtract 21 days.

1st Advent Sunday = (Dec 3) - DOW(Dec 3) days ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ // Nov 27 to Dec 3

Code below assumed date format MM.DDYYYY
Code:
00 { 29-Byte Prgm } 01▸LBL "DIMAVEN" 02 1ᴇ6 03 ÷ 04 12.03   ; Dec 3 05 + 06 ENTER 07 DOW 08 +/- 09 DATE+ 10 END

Since DOW(Dec 3) = DOW(Dec 31), we can even do this in the head, using facts below:

1. Gregorian calendar repeat itself every 400 years.
2. DOW(Dec 31, 2000) = 0 (Sunday)
3. 365 days = 52 weeks + 1 day

Example, Year 2016:

2016 % 400 = 16
leap years count = IP(16/4) - IP(16/100) = 4
DOW(Dec 31, 2016) = (4 + 16) % 7 = 6

(Dec 3, 2016) - 6 days = Nov 27, 2016

Example, Year 2021:

2021 % 400 = 21
leap years count = IP(21/4) - IP(21/100) = 5
DOW(Dec 31, 2021) = (5 + 21) % 7 = 5

(Dec 3, 2021) - 5 days = Nov 28, 2021
01-24-2021, 10:35 AM
Post: #6
 ggauny@live.fr Senior Member Posts: 566 Joined: Nov 2014
RE: (41CX/DM41)(17Bii) Date of the first Advent Sunday in a year
Hi Albert,

Thank for the optimisation !!!
Great.

Gérard.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)