Post Reply 
A tiny New Year's programming challenge
01-02-2015, 10:16 PM (This post was last modified: 01-02-2015 11:31 PM by Gilles.)
Post: #5
RE: A tiny New Year's programming challenge
Hi

There is one error in your test cases :
01 Jan 2012 => week 52/2011, day 7

Here is an HP49/50 version
Work both with the flag 42 set (dd/mm/yy) or not (mm/dd/yy)

Date must be entered with the current HP50g format.Ex

19.081999 IsoWk -> "1999-W33-4" (flag 42 set jj.mmaaa)
12.312012 IsoWk -> "2013-W1-1" (flag 42 not set mm.jjaaaa)

Code:

IsoWk

« 0 400 0 0 → d2 d1 Delta y y1
 «
  -1E-6 1E-6 FOR N
   d2 100 * FP 100 / DUP 'y' STO 1.01 + N + DUP 12.00 TSTR
   N 'y' STO+   
   CASE 1 3 SUB
    DUP "MON" == THEN 0  END
    DUP "TUE" == THEN -1 END
    DUP "WED" == THEN -2 END
    DUP "THU" == THEN -3 END
    DUP "FRI" == THEN 3  END
    DUP "SAT" == THEN 2  END
    DUP "SUN" == THEN 1  END
    0
   END 
   NIP DATE+
   IF DUP d2 DDAYS DUP 0 ≥ THEN
    IF DUP Delta < THEN 'Delta' STO 'd1' STO y 'y1' STO
    ELSE DROP2 END
   ELSE DROP2 END
  1E-6 STEP
  y1 →STR 4 8 SUB "-W" +
  d1 d2 DDAYS 7 IDIV2 1 + UNROT 1 + + "-" + SWAP + 
 » 
»
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 - Gilles - 01-02-2015 10:16 PM



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