Post Reply 
A tiny New Year's programming challenge
01-03-2015, 06:20 PM
Post: #9
RE: A tiny New Year's programming challenge
(01-03-2015 01:24 PM)Gilles Wrote:  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 :
...
[ snip general idea ]
...

Interesting approach.
Just for comparison, I did it this way:
  • Since 4 January is always in week 01, simply determine its weekday (Mon=0 ... Sun=6) and count back this number of days. This is the start of the year's first week.
  • Determine the difference between this day and the entered date.
  • If the result is < 0
          add 7 days to get the day number. The week is the last of the previous year, i.e. 52 or 53.
    else
         divide by 7 and use the integer part and the remainder (both +1) to get week and day number.
         If this result is week 53
              check if it exists
              If it doesn't
                   return week 1 of the next year.
My 34s program includes a short subroutine that returns the last week# for a given year.

By the way:

(01-03-2015 01:24 PM)Gilles Wrote:  - Interger division by 7 (IDIV2 returns integer parts and remainder)

Yes, that's a very handy and useful command. Some time ago I suggested such a command that returns both the integer part and the remainder for the 34s (like DIV in x86 assembly language), but it did not make it into the final firmware. ;-\

(01-03-2015 01:24 PM)Gilles Wrote:  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)

Yes, I used this trick as well. ;-) On the other hand the 34s has a special DATE→ command that assembles year, month and day (given individually) into dd.mmyyyy or mm.ddyyyy or yyyy.mmdd, depending on the current date mode setting.

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-03-2015 06:20 PM



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