Post Reply 
A tiny New Year's programming challenge
01-07-2015, 12:21 AM
Post: #16
RE: A tiny New Year's programming challenge
(01-06-2015 04:11 PM)Werner Wrote:  Here's the two subroutines for 48/49/50 compatibles:

And here's a shorter and slightly more elegant version for the 34s that replaces the original routine at labelĀ 53. It re-uses your idea of emulating a logical OR by a simple multiplication.

Code:
LBL 53    // input: year
CF.01     // output: 51 or 52
LEAP?     // = last week# (0-based)
SF.01
SDR 004
INC X
SDR 002
INC X     // build 01.01yyyy
WDAY      // get weekday of 1 Jan
#004
-         // = zero if year starts on a Thursday (or -1 if on a Wednesday)
ENTER
FS?C.01
INC X     // = zero for a Wednesday in a leap year
*         // = zero if Thursday or (leap year and Wednesday), otherwise positive
SIGN      // turn any non-zero value into 1
+/-
#052
+         // last week# = 52-0 resp. 52-1
RTN

Since local flags are initially cleared, the CF.01 in the second line may even be omitted.

Dieter
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 - Dieter - 01-07-2015 12:21 AM



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