A tiny New Year's programming challenge
|
01-03-2015, 01:24 PM
(This post was last modified: 01-03-2015 05:17 PM by Gilles.)
Post: #8
|
|||
|
|||
RE: A tiny New Year's programming challenge
(01-03-2015 06:58 AM)Dieter Wrote: I have to admit I never used any kind of RPL calculator, so it's a bit difficult for me to figure out how your program works. Would you mind explaining the algorithm, please? Hi dieter, I first tried to handle all the exceptions (negative result etc.) but it looks like marmalade ! So I change to handle all the cases in a single way. The general idea is : Giving a date d2 (dd.mmyyy or mm.ddyyyy format) : -Calculate the first of january for y-1, y , y+1 (the 1e-6 step loop) -for each year, calculte what day is the 1 january (mon, tue, wed ...). For this use the TSTR command and then add or substrat -3...3 days (the CASE serie) - with this, calculate what is the first day of the fisrt week of the year. For this use the DATE+ command - Then calculate the difference between d2 and the calculate fisrt day of the first week of the year. For this use the DDAYS command -> If the result is negative, it is not the 'good' year -> If it is positive, then the smallest delta is the good one (Delta) . You've get the correct year reference (y1) and the correct first day of first week of the year (d1) To finish: - Calculate the number of days between d1 and d2 (DDAYS) - Interger division by 7 (IDIV2 returns integer parts and remainder) - add 1 to each and you get the result Note that there is nothing special to handle dd.mmaaaa or mm.ddaaaa format. The 50G manage this (DATE+ DDAYS TSTR) and by chance (?) 1.012015 means the same thing in the 2 formats (first january) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 5 Guest(s)