A tiny New Year's programming challenge
|
01-07-2015, 01:46 PM
(This post was last modified: 01-07-2015 02:00 PM by Dieter.)
Post: #21
|
|||
|
|||
RE: A tiny New Year's programming challenge
(01-07-2015 08:19 AM)Werner Wrote: Dieter: what's wrong with this? My first ever WP34S try! And no fiddling with flags. There's nothing wrong with it – it works just as well. Your routine checks if the year starts or ends on a Thursday. Which is equivalent to testing if 2 Feb is a Monday OR 2 Feb of the next year is a Tuesday. Your program evaluates this as (weekday(2.2.yyyy) – 1) * (weekday(2.2.yyyy+1) – 2) After omitting the initial CF.01 in my routine, both of our versions require 19 steps. Using NOT instead of SIGN +/– is a good idea – it will save another step. ;-) I should add that I also wanted to use as few calls to date routines as possible in order to speed up the program for calculators that do not offer such functions, so that a single call of WDAY would be preferred. But for such calculators maybe a completely different approach would make more sense. Thank you for your suggestion! Dieter |
|||
01-22-2015, 01:50 PM
Post: #22
|
|||
|
|||
RE: A tiny New Year's programming challenge
I suppose, I'm a bit late for a "New Year's" programming challenge, but I want to contribute a HP-16C program to convert calender date representations.
My solution uses a subroutine to convert a (proleptic) Gregorian Calender date YYYY-MM-DD to a Julian Day Number (i.e. the Julian Date as of YYYY-MM-DDT12:00Z). Code:
ISO 8601 calender date representations:
Convert calendar date to ordinal date or week date using the Julian Day Number JDN(YYYY-MM-DD).
Code:
Usage: DEC {DD} ENTER {MM} ENTER {YYYY} GSB C Display result: YYYY (corrected for calender week) Rdown ww (calender week: 1-53) Rdown D (weekday (1=Mon,...,7=Sun) Rdown YYYYDDD (ISO 8601 ordinal date) Comments are welcome Hartmut |
|||
01-22-2015, 11:24 PM
(This post was last modified: 01-23-2015 10:32 AM by Damien.)
Post: #23
|
|||
|
|||
RE: A tiny New Year's programming challenge
Hi everyone !
Something for HP PRIME: Code:
e.g. 2013.1231 => 2014-W01-2 Regards, Damien |
|||
01-23-2015, 08:25 PM
(This post was last modified: 01-23-2015 08:32 PM by Dieter.)
Post: #24
|
|||
|
|||
RE: A tiny New Year's programming challenge
(01-22-2015 01:50 PM)wynen Wrote: I suppose, I'm a bit late for a "New Year's" programming challenge, but I want to contribute a HP-16C program to convert calender date representations. Thank you very much for your contribution. I do not have access to a 16C, so I cannot try your program. I assume it is based on integer arithmetics. Does it also work for negative (B.C.) years? (01-22-2015 01:50 PM)wynen Wrote: My solution uses a subroutine to convert a (proleptic) Gregorian Calender date YYYY-MM-DD to a Julian Day Number (i.e. the Julian Date as of YYYY-MM-DDT12:00Z). I think it's not mm+12 in the "else" branch, but mm+9. This is also what your program calculates: it first evaluates mm–3 and, if this is <0 (i.e. mm=1..2) it adds 12 back, giving in total mm+9. (01-22-2015 01:50 PM)wynen Wrote: +1, I would say, or use JDN(yyyy-01-00). Otherwise 1 Jan is day 0. (01-22-2015 01:50 PM)wynen Wrote: I think I''ll have to take a closer look at that. Have you tried the examples in my initial post? Dieter |
|||
01-23-2015, 08:39 PM
Post: #25
|
|||
|
|||
RE: A tiny New Year's programming challenge | |||
01-23-2015, 09:47 PM
(This post was last modified: 01-23-2015 10:10 PM by Damien.)
Post: #26
|
|||
|
|||
RE: A tiny New Year's programming challenge
(01-23-2015 08:39 PM)Dieter Wrote:(01-22-2015 11:24 PM)Damien Wrote: Something for HP PRIME: Thanks Dieter, the first time i saw this formula, I immediately thought to the GREAT WP34s and its JDN function. the weeknumber formula was found here: http://www.auduteau.net/calendar/cal5.shtml ( in french Sorry ! ) But it seems to be the translation of (in english): http://www.tondering.dk/claus/cal/week.php (unfortunately where the weeknumber formula has disappeared... And has been remplaced by another formula (the author trial ? - That in some cases don't gives the good answer). Regards, Damien. |
|||
01-23-2015, 10:07 PM
Post: #27
|
|||
|
|||
RE: A tiny New Year's programming challenge
(01-23-2015 09:47 PM)Damien Wrote: the weeknumber formula was found here: No need to apologize. The formula indeed looks promising. I tried some test cases with the 34s and the results look fine. However, a proof or at least an explanation how it works would be nice. Dieter |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)