Post Reply 
A tiny New Year's programming challenge
01-06-2015, 04:11 PM
Post: #15
RE: A tiny New Year's programming challenge
As to making the check more elegant: all I have been able to come up with so far is to try and test for Mondays instead of Thursdays, if the DOW routine returns 0. for Mondays, that is.
A year has 53 weeks if and only if it starts or ends with a Thursday.
A year that starts with a Thursday means 2.02yyyy will be a Monday.
For a year that ends with a Thursday:
Unfortunately, no xx.xxyyyy for x=3..12 (and Jan and Feb of y+1) are Mondays.
No aa.bbyyyy exists for which both aa.bbyyyy and bb.aayyyy are Mondays (so that we can stay independent from the date setting).
So I test 2.02yy+1 for a Tuesday instead..

Here's the two subroutines for 48/49/50 compatibles:

Code:
@ Day Of Week (as a number)
@ In: date (MM.DDYYYY or DD.MMYYYY)
@ Out: 0-6, with 0 being Monday
 DOW
 \<< 1.0119 SWAP DDAYS 7. MOD \>>

Code:
@ number of weeks in year Y
@ In: Year
@ Out: 52 or 53
@ 53 if year starts or ends in a Thursday, else 52
 YW
 \<<
   6. ALOG / 2.02 + DUP DOW       @ year starts on Thursday? = 2.02yyyy is Mo
   SWAP -6. ALOG + DOW 1. \=/    @ year ends on Thursday?   = 2.02yy+1 is Tu
   * NOT 52. +  
 \>>

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: A tiny New Year's programming challenge - Werner - 01-06-2015 04:11 PM



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