Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #56029 > unrolled thread

Find day of week from a given date

Started byMark Wills <markwills1970@gmail.com>
First post2017-03-21 11:51 -0700
Last post2017-03-29 08:23 +0000
Articles 20 on this page of 46 — 11 participants

Back to article view | Back to comp.lang.forth


Contents

  Find day of week from a given date Mark Wills <markwills1970@gmail.com> - 2017-03-21 11:51 -0700
    Re: Find day of week from a given date "Wolfgang Allinger" <all2001@spambog.com> - 2017-03-21 18:17 -0300
      Re: Find day of week from a given date Hans Bezemer <the.beez.speaks@gmail.com> - 2017-03-22 17:47 +0100
        Re: Find day of week from a given date "Wolfgang Allinger" <all2001@spambog.com> - 2017-03-22 20:52 -0300
        Re: Find day of week from a given date Ron Aaron <rambamist@gmail.com> - 2017-03-23 06:57 +0200
    Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-22 19:16 -0700
      Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-22 19:25 -0700
      Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-22 21:28 -0700
        Re: Find day of week from a given date Alex <alex@rivadpm.com> - 2017-03-23 14:12 +0000
          Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-23 16:25 -0700
          Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-23 22:02 -0700
            Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-23 23:07 -0700
            Re: Find day of week from a given date Alex <alex@rivadpm.com> - 2017-03-24 08:46 +0000
      Re: Find day of week from a given date Mark Wills <markwills1970@gmail.com> - 2017-03-23 05:35 -0700
        Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-23 15:23 -0700
          Re: Find day of week from a given date Mark Wills <markwills1970@gmail.com> - 2017-03-24 09:38 -0700
            Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-24 10:24 -0700
              Re: Find day of week from a given date Cecil Bayona <cbayona@cbayona.com> - 2017-03-24 13:32 -0500
                Re: Find day of week from a given date Mark Wills <markwills1970@gmail.com> - 2017-03-24 12:19 -0700
                  Re: Find day of week from a given date Cecil Bayona <cbayona@cbayona.com> - 2017-03-24 16:01 -0500
              Re: Find day of week from a given date Mark Wills <markwills1970@gmail.com> - 2017-03-24 12:00 -0700
                Re: Find day of week from a given date Mark Wills <markwills1970@gmail.com> - 2017-03-24 12:19 -0700
                  Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-24 23:35 -0700
                    Re: Find day of week from a given date Mark Wills <markwills1970@gmail.com> - 2017-03-25 01:59 -0700
                      Re: Find day of week from a given date Julian Fondren <julian.fondren@gmail.com> - 2017-03-25 02:50 -0700
                      Re: Find day of week from a given date Mark Wills <markwills1970@gmail.com> - 2017-03-25 04:37 -0700
                        Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-25 12:32 -0700
                          Re: Find day of week from a given date Cecil Bayona <cbayona@cbayona.com> - 2017-03-25 14:56 -0500
                            Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-26 02:27 -0700
                              Re: Find day of week from a given date Cecil Bayona <cbayona@cbayona.com> - 2017-03-26 14:07 -0500
                Re: Find day of week from a given date Mark Wills <markwills1970@gmail.com> - 2017-03-24 13:17 -0700
                  Re: Find day of week from a given date Howerd <howerdo@yahoo.co.uk> - 2017-03-24 14:43 -0700
                    Re: Find day of week from a given date Mark Wills <markwills1970@gmail.com> - 2017-03-24 15:36 -0700
                    Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-24 23:47 -0700
                  Re: Find day of week from a given date Julian Fondren <julian.fondren@gmail.com> - 2017-03-25 03:00 -0700
                  Re: Find day of week from a given date "Wolfgang Allinger" <all2001@spambog.com> - 2017-03-25 09:06 -0300
              Re: Find day of week from a given date Mark Wills <markwills1970@gmail.com> - 2017-03-24 12:28 -0700
                Re: Find day of week from a given date Julian Fondren <julian.fondren@gmail.com> - 2017-03-24 12:49 -0700
                  Re: Find day of week from a given date Mark Wills <markwills1970@gmail.com> - 2017-03-24 13:15 -0700
              Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-26 14:49 -0700
                Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-26 17:08 -0700
    Re: Find day of week from a given date humptydumpty <ouatubi@gmail.com> - 2017-03-25 04:23 -0700
      Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-26 15:00 -0700
        Re: Find day of week from a given date humptydumpty <ouatubi@gmail.com> - 2017-03-27 00:50 -0700
          Re: Find day of week from a given date hughaguilar96@gmail.com - 2017-03-27 09:14 -0700
    Re: Find day of week from a given date "Robert L." <No_spamming@noWhere_7073.org> - 2017-03-29 08:23 +0000

Page 2 of 3 — ← Prev page 1 [2] 3  Next page →


#56236

FromMark Wills <markwills1970@gmail.com>
Date2017-03-24 12:00 -0700
Message-ID<f5d4e34e-9dba-4f41-8526-4fb014047a66@googlegroups.com>
In reply to#56231
On Friday, 24 March 2017 17:24:26 UTC, hughag...@gmail.com  wrote:
> On Friday, March 24, 2017 at 9:39:00 AM UTC-7, Mark Wills wrote:
> > On Thursday, 23 March 2017 22:23:32 UTC, hughag...@gmail.com  wrote:
> > > On Thursday, March 23, 2017 at 5:35:46 AM UTC-7, Mark Wills wrote:
> > > > On Thursday, 23 March 2017 02:16:27 UTC, hughag...@gmail.com  wrote:
> > > > > I glanced over your code and I was totally confused --- I don't know what you are doing --- I don't think that works.
> > > > 
> > > > It does work. It has had a fairly robust testing.
> > > > 
> > > > Here's the source where I got the explanation and the algorithm:
> > > > 
> > > > http://www.stoimen.com/blog/2012/04/24/computer-algorithms-how-to-determine-the-day-of-the-week/
> > > 
> > > I didn't get my algorithm from anywhere. I just figured it out myself. I won't say that I never make mistakes --- but it is very rare --- this is not an example of me making a mistake.
> > > 
> > > I don't know if you are using Zeller's Algorithm or not. I haven't really looked at your code, the website you referenced, or Zeller's Algorithm very closely. 
> > > 
> > > Here is your code slightly upgraded for testing purposes:
> > > ----------------------------------------------------------------------------
> > > variable year 
> > > variable month 
> > > variable day 
> > > 
> > > create years 0 c, 3 c, 3 c, 6 c, 1 c, 4 c, 6 c, 2 c, 5 c, 0 c, 3 c, 5 c, 
> > > create leap-years 6 c, 2 c, 3 c, 6 c, 1 c, 4 c, 6 c, 2 c, 5 c, 0 c, 3 c, 5 c, 
> > > create centuries 4 c, 2 c, 0 c, 6 c, 
> > > 
> > > : century ( year - n ) 
> > >     1700 /mod drop 100 / 4 mod centuries + c@ ; 
> > > 
> > > : leapYear? ( year - flag ) 
> > >     dup >r 400 mod 0=  r@ 100 mod 0<> or  r> 4 mod 0= and ; 
> > > 
> > > : <dow> ( day month year -- n )                                     \ this was Mark's DOW
> > >     dup century >r  100 mod year !  1- month !  day ! 
> > >     r>  year @ dup 4 /  day @ 
> > >     year @ leapYear? if leap-years else years then month @ + c@ 
> > >     + + + +  7 mod ; 
> > > 
> > > : dow ( month day year -- str )                                     \ this slight upgrade provides a string
> > >     -rot  swap  rot                 \ day month year
> > >     <dow> days ;
> > >     
> > > : test-dow ( month day year -- )
> > >     cr ." Mark: "  3dup dow     count type
> > >     cr ." Hugh: "  day-of-week  count type ;
> > > ----------------------------------------------------------------------------
> > > 
> > > Here is a test:
> > > 
> > > 2 28 1900 test-dow 
> > > Mark: Tuesday
> > > Hugh: Wednesday ok
> > > 3 1 1900 test-dow 
> > > Mark: Thursday
> > > Hugh: Thursday ok
> > > 
> > > You are assuming that 1900 was a leap year --- it isn't.
> > > 
> > > Here, once again for reference, is my code for testing if a year has an extra day or not:
> > > 
> > > : extra-day { year -- 1|0 }             \ how many extra days February gets for this year
> > >     year 4 mod if       0 exit then
> > >     year 100 mod if     1 exit then
> > >     year 400 mod if     0 exit then
> > >     1 ;
> > > 
> > > Here is a test:
> > > 
> > > 1900 extra-day . 0  ok
> > 
> > The problem isn't the leap year calculation. Try my leap year code above:
> > 
> > 1900 leapyear? .
> > 0 ok
> > 
> > See? It's (correctly) not a leap.
> > 
> > The problem (discovered by you) is the algorithm itself as published on
> > 
> > http://www.stoimen.com/blog/2012/04/24/computer-algorithms-how-to-determine-the-day-of-the-week/ 
> > 
> > It says to use the *last two digits of the year*, so I faithfully passed in
> > year mod 100. That results in leapYear? receiving 0 (obviously) which is nonsense year.
> > 
> > I'll modify the code.
> > 
> > It does make one wonder about the quality of some of these descriptions on
> > the web.
> 
> Yes. It is a mistake for people to find algorithms and implement them without understanding how they work. The guy who said to use the "last two digits of the year" most likely found the algorithm in a math book and then posted it on the internet without understanding it, and with minimal testing.
> 
> Now I'm interested in the subject. :-) 
> I'll think on your algorithm and try to figure it out. I'll also write my own code for Zeller's Algorithm and try to figure it out too. It is possible that the mathisfun guys messed up the implementation, but the algorithm actually works. They didn't provide source-code, or explain the algorithm. I don't know how math can be fun if you aren't figuring things out --- using code, or an algorithm, without understanding it is something that a trained monkey could do.
> 
> My own algorithm was just brute-force. I have to loop through the years calling EXTRA-DAY each time until I get to a known year: FIRST-YEAR. This is only realistic with a computer --- nobody would take the time to do this by hand.
> 
> On a related note, check this out: http://www.moonstick.com/
> 
> Also, I have a book on how to build a sundial. There are actually multiple ways to do this. That is another interesting math problem. Building those things could be an interesting hobby. Put one in your front yard! In my hometown I saw people put old tires painted white and filled with soil in their front yard, then grow flowers there --- a sundial would be somewhat less tacky. ;-)
> 
> Keeping track of time is assumed to be the first math problem humans worked on. People had learned arithmetic already, which they used for financial transactions (this is why all the hieroglyphs in English involve money: $ % # etc.). The first actual math involved time though. Also, this is why the five-pointed star is an ancient symbol for religion/science. This is the path that the planet Venus follows along the horizon over a period of about 40 years (the time needed for the orbits of Earth and Venus to synchronize). Venus can be seen with the naked eye. It is possible to build an observatory with stone-age tools that tracks the location of Venus in the sky.

Bruce Fox and I have been playing with this.

This is the shortest we came up with:

0 value day   0 value month   0 value year
: dow ( d m y )
    to year  to month  to day 
    month 2- 12 / year + to year
    month month 2- 12 / 12 * - to month
    month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -  
    year 400 / +  1+  7 mod  case 
    0 of ." Sunday " endof     1 of ." Monday " endof
    2 of ." Tuesday " endof    3 of ." Wednesday " endof
    4 of ." Thursday " endof   5 of ." Friday " endof
    6 of ." Saturday " endof
    endcase ;

[toc] | [prev] | [next] | [standalone]


#56237

FromMark Wills <markwills1970@gmail.com>
Date2017-03-24 12:19 -0700
Message-ID<33f7722b-78f3-4a3c-b76f-81ab736e3365@googlegroups.com>
In reply to#56236
On Friday, 24 March 2017 19:00:48 UTC, Mark Wills  wrote:
> On Friday, 24 March 2017 17:24:26 UTC, hughag...@gmail.com  wrote:
> > On Friday, March 24, 2017 at 9:39:00 AM UTC-7, Mark Wills wrote:
> > > On Thursday, 23 March 2017 22:23:32 UTC, hughag...@gmail.com  wrote:
> > > > On Thursday, March 23, 2017 at 5:35:46 AM UTC-7, Mark Wills wrote:
> > > > > On Thursday, 23 March 2017 02:16:27 UTC, hughag...@gmail.com  wrote:
> > > > > > I glanced over your code and I was totally confused --- I don't know what you are doing --- I don't think that works.
> > > > > 
> > > > > It does work. It has had a fairly robust testing.
> > > > > 
> > > > > Here's the source where I got the explanation and the algorithm:
> > > > > 
> > > > > http://www.stoimen.com/blog/2012/04/24/computer-algorithms-how-to-determine-the-day-of-the-week/
> > > > 
> > > > I didn't get my algorithm from anywhere. I just figured it out myself. I won't say that I never make mistakes --- but it is very rare --- this is not an example of me making a mistake.
> > > > 
> > > > I don't know if you are using Zeller's Algorithm or not. I haven't really looked at your code, the website you referenced, or Zeller's Algorithm very closely. 
> > > > 
> > > > Here is your code slightly upgraded for testing purposes:
> > > > ----------------------------------------------------------------------------
> > > > variable year 
> > > > variable month 
> > > > variable day 
> > > > 
> > > > create years 0 c, 3 c, 3 c, 6 c, 1 c, 4 c, 6 c, 2 c, 5 c, 0 c, 3 c, 5 c, 
> > > > create leap-years 6 c, 2 c, 3 c, 6 c, 1 c, 4 c, 6 c, 2 c, 5 c, 0 c, 3 c, 5 c, 
> > > > create centuries 4 c, 2 c, 0 c, 6 c, 
> > > > 
> > > > : century ( year - n ) 
> > > >     1700 /mod drop 100 / 4 mod centuries + c@ ; 
> > > > 
> > > > : leapYear? ( year - flag ) 
> > > >     dup >r 400 mod 0=  r@ 100 mod 0<> or  r> 4 mod 0= and ; 
> > > > 
> > > > : <dow> ( day month year -- n )                                     \ this was Mark's DOW
> > > >     dup century >r  100 mod year !  1- month !  day ! 
> > > >     r>  year @ dup 4 /  day @ 
> > > >     year @ leapYear? if leap-years else years then month @ + c@ 
> > > >     + + + +  7 mod ; 
> > > > 
> > > > : dow ( month day year -- str )                                     \ this slight upgrade provides a string
> > > >     -rot  swap  rot                 \ day month year
> > > >     <dow> days ;
> > > >     
> > > > : test-dow ( month day year -- )
> > > >     cr ." Mark: "  3dup dow     count type
> > > >     cr ." Hugh: "  day-of-week  count type ;
> > > > ----------------------------------------------------------------------------
> > > > 
> > > > Here is a test:
> > > > 
> > > > 2 28 1900 test-dow 
> > > > Mark: Tuesday
> > > > Hugh: Wednesday ok
> > > > 3 1 1900 test-dow 
> > > > Mark: Thursday
> > > > Hugh: Thursday ok
> > > > 
> > > > You are assuming that 1900 was a leap year --- it isn't.
> > > > 
> > > > Here, once again for reference, is my code for testing if a year has an extra day or not:
> > > > 
> > > > : extra-day { year -- 1|0 }             \ how many extra days February gets for this year
> > > >     year 4 mod if       0 exit then
> > > >     year 100 mod if     1 exit then
> > > >     year 400 mod if     0 exit then
> > > >     1 ;
> > > > 
> > > > Here is a test:
> > > > 
> > > > 1900 extra-day . 0  ok
> > > 
> > > The problem isn't the leap year calculation. Try my leap year code above:
> > > 
> > > 1900 leapyear? .
> > > 0 ok
> > > 
> > > See? It's (correctly) not a leap.
> > > 
> > > The problem (discovered by you) is the algorithm itself as published on
> > > 
> > > http://www.stoimen.com/blog/2012/04/24/computer-algorithms-how-to-determine-the-day-of-the-week/ 
> > > 
> > > It says to use the *last two digits of the year*, so I faithfully passed in
> > > year mod 100. That results in leapYear? receiving 0 (obviously) which is nonsense year.
> > > 
> > > I'll modify the code.
> > > 
> > > It does make one wonder about the quality of some of these descriptions on
> > > the web.
> > 
> > Yes. It is a mistake for people to find algorithms and implement them without understanding how they work. The guy who said to use the "last two digits of the year" most likely found the algorithm in a math book and then posted it on the internet without understanding it, and with minimal testing.
> > 
> > Now I'm interested in the subject. :-) 
> > I'll think on your algorithm and try to figure it out. I'll also write my own code for Zeller's Algorithm and try to figure it out too. It is possible that the mathisfun guys messed up the implementation, but the algorithm actually works. They didn't provide source-code, or explain the algorithm. I don't know how math can be fun if you aren't figuring things out --- using code, or an algorithm, without understanding it is something that a trained monkey could do.
> > 
> > My own algorithm was just brute-force. I have to loop through the years calling EXTRA-DAY each time until I get to a known year: FIRST-YEAR. This is only realistic with a computer --- nobody would take the time to do this by hand.
> > 
> > On a related note, check this out: http://www.moonstick.com/
> > 
> > Also, I have a book on how to build a sundial. There are actually multiple ways to do this. That is another interesting math problem. Building those things could be an interesting hobby. Put one in your front yard! In my hometown I saw people put old tires painted white and filled with soil in their front yard, then grow flowers there --- a sundial would be somewhat less tacky. ;-)
> > 
> > Keeping track of time is assumed to be the first math problem humans worked on. People had learned arithmetic already, which they used for financial transactions (this is why all the hieroglyphs in English involve money: $ % # etc.). The first actual math involved time though. Also, this is why the five-pointed star is an ancient symbol for religion/science. This is the path that the planet Venus follows along the horizon over a period of about 40 years (the time needed for the orbits of Earth and Venus to synchronize). Venus can be seen with the naked eye. It is possible to build an observatory with stone-age tools that tracks the location of Venus in the sky.
> 
> Bruce Fox and I have been playing with this.
> 
> This is the shortest we came up with:
> 
> 0 value day   0 value month   0 value year
> : dow ( d m y )
>     to year  to month  to day 
>     month 2- 12 / year + to year
>     month month 2- 12 / 12 * - to month
>     month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -  
>     year 400 / +  1+  7 mod  case 
>     0 of ." Sunday " endof     1 of ." Monday " endof
>     2 of ." Tuesday " endof    3 of ." Wednesday " endof
>     4 of ." Thursday " endof   5 of ." Friday " endof
>     6 of ." Saturday " endof
>     endcase ;

I've tested the above with a bunch of dates using http://www.calculatorcat.com/date/day-of-week.html and it seems to be
working flawlessly.

[toc] | [prev] | [next] | [standalone]


#56259

Fromhughaguilar96@gmail.com
Date2017-03-24 23:35 -0700
Message-ID<1abeb064-ab5c-4e95-bd65-2cdd8fb2de48@googlegroups.com>
In reply to#56237
On Friday, March 24, 2017 at 12:19:14 PM UTC-7, Mark Wills wrote:
> On Friday, 24 March 2017 19:00:48 UTC, Mark Wills  wrote:
> > Bruce Fox and I have been playing with this.
> > 
> > This is the shortest we came up with:
> > 
> > 0 value day   0 value month   0 value year
> > : dow ( d m y )
> >     to year  to month  to day 
> >     month 2- 12 / year + to year
> >     month month 2- 12 / 12 * - to month
> >     month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -  
> >     year 400 / +  1+  7 mod  case 
> >     0 of ." Sunday " endof     1 of ." Monday " endof
> >     2 of ." Tuesday " endof    3 of ." Wednesday " endof
> >     4 of ." Thursday " endof   5 of ." Friday " endof
> >     6 of ." Saturday " endof
> >     endcase ;
> 
> I've tested the above with a bunch of dates using http://www.calculatorcat.com/date/day-of-week.html and it seems to be
> working flawlessly.

What??? I tried the same test as before, and it failed again.

Here is your code modified slightly by me for readability:

: dow { month day year -- str }
    month 2 - 12 /  year +  to year
    month  month 2 - 12 / 12 *  -  to month
    month 2 * day +  month 1 + 6 * 10 /  +  year +  year 4 /  +  year 100 / -
    year 400 / +  1 +  7 mod  days ;
    
: test-dow ( month day year -- )
    cr ." Mark: "  3dup dow     count type
    cr ." Hugh: "  day-of-week  count type ;

Here is the test:

2 28 1900 test-dow 
Mark: Sunday
Hugh: Wednesday ok

3 1 1900 test-dow 
Mark: Thursday
Hugh: Thursday ok

This is CalculatorCat:

2 28 1900 --- Wednesday
3  1 1900 --- Thursday

AFAIK, my code agrees with CalculatorCat in all cases.

[toc] | [prev] | [next] | [standalone]


#56265

FromMark Wills <markwills1970@gmail.com>
Date2017-03-25 01:59 -0700
Message-ID<2f4fe571-70f4-4979-9e8c-a094f0d808cd@googlegroups.com>
In reply to#56259
On Saturday, 25 March 2017 06:35:13 UTC, hughag...@gmail.com  wrote:
> On Friday, March 24, 2017 at 12:19:14 PM UTC-7, Mark Wills wrote:
> > On Friday, 24 March 2017 19:00:48 UTC, Mark Wills  wrote:
> > > Bruce Fox and I have been playing with this.
> > > 
> > > This is the shortest we came up with:
> > > 
> > > 0 value day   0 value month   0 value year
> > > : dow ( d m y )
> > >     to year  to month  to day 
> > >     month 2- 12 / year + to year
> > >     month month 2- 12 / 12 * - to month
> > >     month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -  
> > >     year 400 / +  1+  7 mod  case 
> > >     0 of ." Sunday " endof     1 of ." Monday " endof
> > >     2 of ." Tuesday " endof    3 of ." Wednesday " endof
> > >     4 of ." Thursday " endof   5 of ." Friday " endof
> > >     6 of ." Saturday " endof
> > >     endcase ;
> > 
> > I've tested the above with a bunch of dates using http://www.calculatorcat.com/date/day-of-week.html and it seems to be
> > working flawlessly.
> 
> What??? I tried the same test as before, and it failed again.
> 
> Here is your code modified slightly by me for readability:
> 
> : dow { month day year -- str }
>     month 2 - 12 /  year +  to year
>     month  month 2 - 12 / 12 *  -  to month
>     month 2 * day +  month 1 + 6 * 10 /  +  year +  year 4 /  +  year 100 / -
>     year 400 / +  1 +  7 mod  days ;
>     
> : test-dow ( month day year -- )
>     cr ." Mark: "  3dup dow     count type
>     cr ." Hugh: "  day-of-week  count type ;
> 
> Here is the test:
> 
> 2 28 1900 test-dow 
> Mark: Sunday
> Hugh: Wednesday ok
> 
> 3 1 1900 test-dow 
> Mark: Thursday
> Hugh: Thursday ok
> 
> This is CalculatorCat:
> 
> 2 28 1900 --- Wednesday
> 3  1 1900 --- Thursday
> 
> AFAIK, my code agrees with CalculatorCat in all cases.

Well that's bizzaro... It's working okay in TurboForth.

Please see: http://turboforth.net/images/dow.png

[toc] | [prev] | [next] | [standalone]


#56267

FromJulian Fondren <julian.fondren@gmail.com>
Date2017-03-25 02:50 -0700
Message-ID<f2b975fb-fb14-4268-9cbd-0a1db9f01be1@googlegroups.com>
In reply to#56265
On Saturday, March 25, 2017 at 3:59:33 AM UTC-5, Mark Wills wrote:
> On Saturday, 25 March 2017 06:35:13 UTC, hughag...@gmail.com  wrote:
> > On Friday, March 24, 2017 at 12:19:14 PM UTC-7, Mark Wills wrote:
> > > On Friday, 24 March 2017 19:00:48 UTC, Mark Wills  wrote:
> > > > Bruce Fox and I have been playing with this.
> > > > 
> > > > This is the shortest we came up with:
> > > > 
> > > > 0 value day   0 value month   0 value year
> > > > : dow ( d m y )
> > > >     to year  to month  to day 
> > > >     month 2- 12 / year + to year
> > > >     month month 2- 12 / 12 * - to month
> > > >     month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -  
> > > >     year 400 / +  1+  7 mod  case 
> > > >     0 of ." Sunday " endof     1 of ." Monday " endof
> > > >     2 of ." Tuesday " endof    3 of ." Wednesday " endof
> > > >     4 of ." Thursday " endof   5 of ." Friday " endof
> > > >     6 of ." Saturday " endof
> > > >     endcase ;
> > > 
> > > I've tested the above with a bunch of dates using http://www.calculatorcat.com/date/day-of-week.html and it seems to be
> > > working flawlessly.
> > 
> > What??? I tried the same test as before, and it failed again.
> > 
> > Here is your code modified slightly by me for readability:
> > 
> > : dow { month day year -- str }
> >     month 2 - 12 /  year +  to year
> >     month  month 2 - 12 / 12 *  -  to month
> >     month 2 * day +  month 1 + 6 * 10 /  +  year +  year 4 /  +  year 100 / -
> >     year 400 / +  1 +  7 mod  days ;
> >     
> > : test-dow ( month day year -- )
> >     cr ." Mark: "  3dup dow     count type
> >     cr ." Hugh: "  day-of-week  count type ;
> > 
> > Here is the test:
> > 
> > 2 28 1900 test-dow 
> > Mark: Sunday
> > Hugh: Wednesday ok
> > 
> > 3 1 1900 test-dow 
> > Mark: Thursday
> > Hugh: Thursday ok
> > 
> > This is CalculatorCat:
> > 
> > 2 28 1900 --- Wednesday
> > 3  1 1900 --- Thursday
> > 
> > AFAIK, my code agrees with CalculatorCat in all cases.
> 
> Well that's bizzaro... It's working okay in TurboForth.
> 
> Please see: http://turboforth.net/images/dow.png

It should compile on anything after 2- is defined.

There is no "Y-DD".

[toc] | [prev] | [next] | [standalone]


#56274

FromMark Wills <markwills1970@gmail.com>
Date2017-03-25 04:37 -0700
Message-ID<88e012f1-9d6b-4f87-a61a-88e98aff8f66@googlegroups.com>
In reply to#56265
On Saturday, 25 March 2017 08:59:33 UTC, Mark Wills  wrote:
> On Saturday, 25 March 2017 06:35:13 UTC, hughag...@gmail.com  wrote:
> > On Friday, March 24, 2017 at 12:19:14 PM UTC-7, Mark Wills wrote:
> > > On Friday, 24 March 2017 19:00:48 UTC, Mark Wills  wrote:
> > > > Bruce Fox and I have been playing with this.
> > > > 
> > > > This is the shortest we came up with:
> > > > 
> > > > 0 value day   0 value month   0 value year
> > > > : dow ( d m y )
> > > >     to year  to month  to day 
> > > >     month 2- 12 / year + to year
> > > >     month month 2- 12 / 12 * - to month
> > > >     month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -  
> > > >     year 400 / +  1+  7 mod  case 
> > > >     0 of ." Sunday " endof     1 of ." Monday " endof
> > > >     2 of ." Tuesday " endof    3 of ." Wednesday " endof
> > > >     4 of ." Thursday " endof   5 of ." Friday " endof
> > > >     6 of ." Saturday " endof
> > > >     endcase ;
> > > 
> > > I've tested the above with a bunch of dates using http://www.calculatorcat.com/date/day-of-week.html and it seems to be
> > > working flawlessly.
> > 
> > What??? I tried the same test as before, and it failed again.
> > 
> > Here is your code modified slightly by me for readability:
> > 
> > : dow { month day year -- str }
> >     month 2 - 12 /  year +  to year
> >     month  month 2 - 12 / 12 *  -  to month
> >     month 2 * day +  month 1 + 6 * 10 /  +  year +  year 4 /  +  year 100 / -
> >     year 400 / +  1 +  7 mod  days ;
> >     
> > : test-dow ( month day year -- )
> >     cr ." Mark: "  3dup dow     count type
> >     cr ." Hugh: "  day-of-week  count type ;
> > 
> > Here is the test:
> > 
> > 2 28 1900 test-dow 
> > Mark: Sunday
> > Hugh: Wednesday ok
> > 
> > 3 1 1900 test-dow 
> > Mark: Thursday
> > Hugh: Thursday ok
> > 
> > This is CalculatorCat:
> > 
> > 2 28 1900 --- Wednesday
> > 3  1 1900 --- Thursday
> > 
> > AFAIK, my code agrees with CalculatorCat in all cases.
> 
> Well that's bizzaro... It's working okay in TurboForth.
> 
> Please see: http://turboforth.net/images/dow.png

Ah. Hang on. You changed month and day around. I didn't notice that.
Back to the drawing board...

[toc] | [prev] | [next] | [standalone]


#56289

Fromhughaguilar96@gmail.com
Date2017-03-25 12:32 -0700
Message-ID<7e825531-2d8e-491d-81a7-186929798086@googlegroups.com>
In reply to#56274
On Saturday, March 25, 2017 at 4:37:09 AM UTC-7, Mark Wills wrote:
> On Saturday, 25 March 2017 08:59:33 UTC, Mark Wills  wrote:
> > On Saturday, 25 March 2017 06:35:13 UTC, hughag...@gmail.com  wrote:
> > > On Friday, March 24, 2017 at 12:19:14 PM UTC-7, Mark Wills wrote:
> > > > On Friday, 24 March 2017 19:00:48 UTC, Mark Wills  wrote:
> > > > > Bruce Fox and I have been playing with this.
> > > > > 
> > > > > This is the shortest we came up with:
> > > > > 
> > > > > 0 value day   0 value month   0 value year
> > > > > : dow ( d m y )
> > > > >     to year  to month  to day 
> > > > >     month 2- 12 / year + to year
> > > > >     month month 2- 12 / 12 * - to month
> > > > >     month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -  
> > > > >     year 400 / +  1+  7 mod  case 
> > > > >     0 of ." Sunday " endof     1 of ." Monday " endof
> > > > >     2 of ." Tuesday " endof    3 of ." Wednesday " endof
> > > > >     4 of ." Thursday " endof   5 of ." Friday " endof
> > > > >     6 of ." Saturday " endof
> > > > >     endcase ;
> > > > 
> > > > I've tested the above with a bunch of dates using http://www.calculatorcat.com/date/day-of-week.html and it seems to be
> > > > working flawlessly.
> > > 
> > > What??? I tried the same test as before, and it failed again.
> > > 
> > > Here is your code modified slightly by me for readability:
> > > 
> > > : dow { month day year -- str }
> > >     month 2 - 12 /  year +  to year
> > >     month  month 2 - 12 / 12 *  -  to month
> > >     month 2 * day +  month 1 + 6 * 10 /  +  year +  year 4 /  +  year 100 / -
> > >     year 400 / +  1 +  7 mod  days ;
> > >     
> > > : test-dow ( month day year -- )
> > >     cr ." Mark: "  3dup dow     count type
> > >     cr ." Hugh: "  day-of-week  count type ;
> > > 
> > > Here is the test:
> > > 
> > > 2 28 1900 test-dow 
> > > Mark: Sunday
> > > Hugh: Wednesday ok
> > > 
> > > 3 1 1900 test-dow 
> > > Mark: Thursday
> > > Hugh: Thursday ok
> > > 
> > > This is CalculatorCat:
> > > 
> > > 2 28 1900 --- Wednesday
> > > 3  1 1900 --- Thursday
> > > 
> > > AFAIK, my code agrees with CalculatorCat in all cases.
> > 
> > Well that's bizzaro... It's working okay in TurboForth.
> > 
> > Please see: http://turboforth.net/images/dow.png
> 
> Ah. Hang on. You changed month and day around. I didn't notice that.
> Back to the drawing board...

I agree that day/month/year would make more sense than month/day/year because it is ascending. But everybody in America uses month/day/year and their minds are fixed. Is day/month/year used in other countries?

I also think that base-6 would make more sense than base-10 --- but humans have been using base-10 for thousands of years --- I read somewhere that aboriginals in Ecuador use base-6, but I don't know if that is true.

The Japanese (maybe all Asians) write the surname first, then the given name. This makes more sense because it helps when doing a look-up, such as in a telephone book. But that is not how it is done in the Western world, and it is too late to change.

The English are notorious for being obstinate and doing things different than everybody else, all on the theory that they are the superior race and anything invented by an Englishman must necessarily be superior. For example, the Enfield rifle has the rifling in the opposite direction of everybody else in the world. When you stick a cleaning rod in, the attachment on the end unscrews and can get stuck in the barrel, which is extremely dangerous if you don't notice and then fire the rifle (hopefully your left eye was your good eye, because that is the only one you will have still functioning; and, if you weren't handsome to start with, you won't be too disappointed in your face afterward). But why do the English do it differently? What difference does it make whether the bullet spins counter-clockwise or clockwise in the air? The purpose of spinning is stabilization, but this works the same with either spin. So why not just do it the same way as everybody else? The English are just being arrogant and obstinate --- they did it backwards because they weren't thinking, way back in the late 19th century --- now they are married to the mistake and refuse to change.

[toc] | [prev] | [next] | [standalone]


#56291

FromCecil Bayona <cbayona@cbayona.com>
Date2017-03-25 14:56 -0500
Message-ID<ob6hrq$v34$1@dont-email.me>
In reply to#56289
On 3/25/2017 2:32 PM, hughaguilar96@gmail.com wrote:
> On Saturday, March 25, 2017 at 4:37:09 AM UTC-7, Mark Wills wrote:
>> On Saturday, 25 March 2017 08:59:33 UTC, Mark Wills  wrote:
>>> On Saturday, 25 March 2017 06:35:13 UTC, hughag...@gmail.com  wrote:
>>>> On Friday, March 24, 2017 at 12:19:14 PM UTC-7, Mark Wills wrote:
>>>>> On Friday, 24 March 2017 19:00:48 UTC, Mark Wills  wrote:
>>>>>> Bruce Fox and I have been playing with this.
>>>>>>
>>>>>> This is the shortest we came up with:
>>>>>>
>>>>>> 0 value day   0 value month   0 value year
>>>>>> : dow ( d m y )
>>>>>>     to year  to month  to day
>>>>>>     month 2- 12 / year + to year
>>>>>>     month month 2- 12 / 12 * - to month
>>>>>>     month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -
>>>>>>     year 400 / +  1+  7 mod  case
>>>>>>     0 of ." Sunday " endof     1 of ." Monday " endof
>>>>>>     2 of ." Tuesday " endof    3 of ." Wednesday " endof
>>>>>>     4 of ." Thursday " endof   5 of ." Friday " endof
>>>>>>     6 of ." Saturday " endof
>>>>>>     endcase ;
>>>>>
>>>>> I've tested the above with a bunch of dates using http://www.calculatorcat.com/date/day-of-week.html and it seems to be
>>>>> working flawlessly.
>>>>
>>>> What??? I tried the same test as before, and it failed again.
>>>>
>>>> Here is your code modified slightly by me for readability:
>>>>
>>>> : dow { month day year -- str }
>>>>     month 2 - 12 /  year +  to year
>>>>     month  month 2 - 12 / 12 *  -  to month
>>>>     month 2 * day +  month 1 + 6 * 10 /  +  year +  year 4 /  +  year 100 / -
>>>>     year 400 / +  1 +  7 mod  days ;
>>>>
>>>> : test-dow ( month day year -- )
>>>>     cr ." Mark: "  3dup dow     count type
>>>>     cr ." Hugh: "  day-of-week  count type ;
>>>>
>>>> Here is the test:
>>>>
>>>> 2 28 1900 test-dow
>>>> Mark: Sunday
>>>> Hugh: Wednesday ok
>>>>
>>>> 3 1 1900 test-dow
>>>> Mark: Thursday
>>>> Hugh: Thursday ok
>>>>
>>>> This is CalculatorCat:
>>>>
>>>> 2 28 1900 --- Wednesday
>>>> 3  1 1900 --- Thursday
>>>>
>>>> AFAIK, my code agrees with CalculatorCat in all cases.
>>>
>>> Well that's bizzaro... It's working okay in TurboForth.
>>>
>>> Please see: http://turboforth.net/images/dow.png
>>
>> Ah. Hang on. You changed month and day around. I didn't notice that.
>> Back to the drawing board...
>
> I agree that day/month/year would make more sense than month/day/year because it is ascending. But everybody in America uses month/day/year and their minds are fixed. Is day/month/year used in other countries?
>
> I also think that base-6 would make more sense than base-10 --- but humans have been using base-10 for thousands of years --- I read somewhere that aboriginals in Ecuador use base-6, but I don't know if that is true.
>
> The Japanese (maybe all Asians) write the surname first, then the given name. This makes more sense because it helps when doing a look-up, such as in a telephone book. But that is not how it is done in the Western world, and it is too late to change.
>
> The English are notorious for being obstinate and doing things different than everybody else, all on the theory that they are the superior race and anything invented by an Englishman must necessarily be superior. For example, the Enfield rifle has the rifling in the opposite direction of everybody else in the world. When you stick a cleaning rod in, the attachment on the end unscrews and can get stuck in the barrel, which is extremely dangerous if you don't notice and then fire the rifle (hopefully your left eye was your good eye, because that is the only one you will have still functioning; and, if you weren't handsome to start with, you won't be too disappointed in your face afterward). But why do the English do it differently? What difference does it make whether the bullet spins counter-clockwise or clockwise in the air? The purpose of spinning is stabilization, but this works the same with either spin. So why not just do it the same way as everybody else? The English are just being arrogant and obstinate --- they did it backwards because they weren't thinking, way back in the late 19th century --- now they are married to the mistake and refuse to change.
>

Ah but the Lee Enfield had many advantages over other bolt action rifles.

It was much faster than other rifles of the bolt action era because it 
had a shorter throw on the bolt, that made you more accurate while 
multiple firing since the bold did not hit your face and you had to take 
the rifle away from your face while cocking. Unlike the Mouser 98 
action, the lock was in the back instead of the front that helped it 
have a shorter throw. It packed 10 rounds of ammunition instead of your 
typical 5 rounds and because it used an external magazine it could be 
loaded faster. So it had a lot of improvements to it's one odd thing but 
that did not make a difference anyway. Cleaning rods are available with 
reverse threads so having the right cleaning rod can be done. Everyone 
thinks their culture is the best, nothing new there.


-- 
Cecil - k5nwa

[toc] | [prev] | [next] | [standalone]


#56332

Fromhughaguilar96@gmail.com
Date2017-03-26 02:27 -0700
Message-ID<2cb6938d-bd36-4ca1-a7fa-fc698828d01d@googlegroups.com>
In reply to#56291
On Saturday, March 25, 2017 at 12:56:29 PM UTC-7, Cecil - k5nwa wrote:
> On 3/25/2017 2:32 PM, hughaguilar96@gmail.com wrote:
> > I agree that day/month/year would make more sense than month/day/year because it is ascending. But everybody in America uses month/day/year and their minds are fixed. Is day/month/year used in other countries?
> >
> > I also think that base-6 would make more sense than base-10 --- but humans have been using base-10 for thousands of years --- I read somewhere that aboriginals in Ecuador use base-6, but I don't know if that is true.
> >
> > The Japanese (maybe all Asians) write the surname first, then the given name. This makes more sense because it helps when doing a look-up, such as in a telephone book. But that is not how it is done in the Western world, and it is too late to change.
> >
> > The English are notorious for being obstinate and doing things different than everybody else, all on the theory that they are the superior race and anything invented by an Englishman must necessarily be superior. For example, the Enfield rifle has the rifling in the opposite direction of everybody else in the world. When you stick a cleaning rod in, the attachment on the end unscrews and can get stuck in the barrel, which is extremely dangerous if you don't notice and then fire the rifle (hopefully your left eye was your good eye, because that is the only one you will have still functioning; and, if you weren't handsome to start with, you won't be too disappointed in your face afterward). But why do the English do it differently? What difference does it make whether the bullet spins counter-clockwise or clockwise in the air? The purpose of spinning is stabilization, but this works the same with either spin. So why not just do it the same way as everybody else? The English are just being arrogant and obstinate --- they did it backwards because they weren't thinking, way back in the late 19th century --- now they are married to the mistake and refuse to change.
> >
> 
> Ah but the Lee Enfield had many advantages over other bolt action rifles.
> 
> It was much faster than other rifles of the bolt action era because it 
> had a shorter throw on the bolt, that made you more accurate while 
> multiple firing since the bold did not hit your face and you had to take 
> the rifle away from your face while cocking. Unlike the Mouser 98 
> action, the lock was in the back instead of the front that helped it 
> have a shorter throw. It packed 10 rounds of ammunition instead of your 
> typical 5 rounds and because it used an external magazine it could be 
> loaded faster. So it had a lot of improvements to it's one odd thing but 
> that did not make a difference anyway. Cleaning rods are available with 
> reverse threads so having the right cleaning rod can be done. Everyone 
> thinks their culture is the best, nothing new there.

Actually, I like the Enfield --- of all those WWII surplus rifles floating around, getting sold for $100, it is likely the best --- I would rather have an Enfield than an AK-47 or SKS in a post-apocalyptic world.

The point I was making, is that people get married to a mistake, and then they obstinately refuse to change --- it is best to change early, while it is minimally painful to do so --- actually, the Enfield design could have been changed at any time with almost no pain (everybody who had invested $10 in a reverse-threaded cleaning rod would have to buy a normal one and discard their goofy reverse-threaded one).

Another point I was making, is that after it becomes too late to change, it is a waste of energy to try to change --- it is also a bad idea to get married to an obscure technology, and ignore the mainstream world --- for example: I think the .327-magnum is a slightly better pistol for women than the .38-special, but I don't recommend that anybody buy it because ammo will be nearly impossible to find.

[toc] | [prev] | [next] | [standalone]


#56351

FromCecil Bayona <cbayona@cbayona.com>
Date2017-03-26 14:07 -0500
Message-ID<ob93cn$qvm$1@dont-email.me>
In reply to#56332
On 3/26/2017 4:27 AM, hughaguilar96@gmail.com wrote:
> On Saturday, March 25, 2017 at 12:56:29 PM UTC-7, Cecil - k5nwa wrote:
>> On 3/25/2017 2:32 PM, hughaguilar96@gmail.com wrote:
>>> I agree that day/month/year would make more sense than month/day/year because it is ascending. But everybody in America uses month/day/year and their minds are fixed. Is day/month/year used in other countries?
>>>
>>> I also think that base-6 would make more sense than base-10 --- but humans have been using base-10 for thousands of years --- I read somewhere that aboriginals in Ecuador use base-6, but I don't know if that is true.
>>>
>>> The Japanese (maybe all Asians) write the surname first, then the given name. This makes more sense because it helps when doing a look-up, such as in a telephone book. But that is not how it is done in the Western world, and it is too late to change.
>>>
>>> The English are notorious for being obstinate and doing things different than everybody else, all on the theory that they are the superior race and anything invented by an Englishman must necessarily be superior. For example, the Enfield rifle has the rifling in the opposite direction of everybody else in the world. When you stick a cleaning rod in, the attachment on the end unscrews and can get stuck in the barrel, which is extremely dangerous if you don't notice and then fire the rifle (hopefully your left eye was your good eye, because that is the only one you will have still functioning; and, if you weren't handsome to start with, you won't be too disappointed in your face afterward). But why do the English do it differently? What difference does it make whether the bullet spins counter-clockwise or clockwise in the air? The purpose of spinning is stabilization, but this works the same with either spin. So why not just do it the same way as everybody else? The English are just being arrogant and obstinate --- they did it backwards because they weren't thinking, way back in the late 19th century --- now they are married to the mistake and refuse to change.
>>>
>>
>> Ah but the Lee Enfield had many advantages over other bolt action rifles.
>>
>> It was much faster than other rifles of the bolt action era because it
>> had a shorter throw on the bolt, that made you more accurate while
>> multiple firing since the bold did not hit your face and you had to take
>> the rifle away from your face while cocking. Unlike the Mouser 98
>> action, the lock was in the back instead of the front that helped it
>> have a shorter throw. It packed 10 rounds of ammunition instead of your
>> typical 5 rounds and because it used an external magazine it could be
>> loaded faster. So it had a lot of improvements to it's one odd thing but
>> that did not make a difference anyway. Cleaning rods are available with
>> reverse threads so having the right cleaning rod can be done. Everyone
>> thinks their culture is the best, nothing new there.
>
> Actually, I like the Enfield --- of all those WWII surplus rifles floating around, getting sold for $100, it is likely the best --- I would rather have an Enfield than an AK-47 or SKS in a post-apocalyptic world.
>
> The point I was making, is that people get married to a mistake, and then they obstinately refuse to change --- it is best to change early, while it is minimally painful to do so --- actually, the Enfield design could have been changed at any time with almost no pain (everybody who had invested $10 in a reverse-threaded cleaning rod would have to buy a normal one and discard their goofy reverse-threaded one).
>
> Another point I was making, is that after it becomes too late to change, it is a waste of energy to try to change --- it is also a bad idea to get married to an obscure technology, and ignore the mainstream world --- for example: I think the .327-magnum is a slightly better pistol for women than the .38-special, but I don't recommend that anybody buy it because ammo will be nearly impossible to find.
>
I'm aware of your point, just showing interesting facts about the Lee 
Enfield rifle, all about it was not due to stubbornness, actually I 
believe that the Enfield was the first repeating (not 100% sure) bolt 
action rifle so it was the rest of the world that went it's own way.

-- 
Cecil - k5nwa

[toc] | [prev] | [next] | [standalone]


#56242

FromMark Wills <markwills1970@gmail.com>
Date2017-03-24 13:17 -0700
Message-ID<8032bba9-fb6d-4084-b730-c76381b3b8e0@googlegroups.com>
In reply to#56236
On Friday, 24 March 2017 19:00:48 UTC, Mark Wills  wrote:
> On Friday, 24 March 2017 17:24:26 UTC, hughag...@gmail.com  wrote:
> > On Friday, March 24, 2017 at 9:39:00 AM UTC-7, Mark Wills wrote:
> > > On Thursday, 23 March 2017 22:23:32 UTC, hughag...@gmail.com  wrote:
> > > > On Thursday, March 23, 2017 at 5:35:46 AM UTC-7, Mark Wills wrote:
> > > > > On Thursday, 23 March 2017 02:16:27 UTC, hughag...@gmail.com  wrote:
> > > > > > I glanced over your code and I was totally confused --- I don't know what you are doing --- I don't think that works.
> > > > > 
> > > > > It does work. It has had a fairly robust testing.
> > > > > 
> > > > > Here's the source where I got the explanation and the algorithm:
> > > > > 
> > > > > http://www.stoimen.com/blog/2012/04/24/computer-algorithms-how-to-determine-the-day-of-the-week/
> > > > 
> > > > I didn't get my algorithm from anywhere. I just figured it out myself. I won't say that I never make mistakes --- but it is very rare --- this is not an example of me making a mistake.
> > > > 
> > > > I don't know if you are using Zeller's Algorithm or not. I haven't really looked at your code, the website you referenced, or Zeller's Algorithm very closely. 
> > > > 
> > > > Here is your code slightly upgraded for testing purposes:
> > > > ----------------------------------------------------------------------------
> > > > variable year 
> > > > variable month 
> > > > variable day 
> > > > 
> > > > create years 0 c, 3 c, 3 c, 6 c, 1 c, 4 c, 6 c, 2 c, 5 c, 0 c, 3 c, 5 c, 
> > > > create leap-years 6 c, 2 c, 3 c, 6 c, 1 c, 4 c, 6 c, 2 c, 5 c, 0 c, 3 c, 5 c, 
> > > > create centuries 4 c, 2 c, 0 c, 6 c, 
> > > > 
> > > > : century ( year - n ) 
> > > >     1700 /mod drop 100 / 4 mod centuries + c@ ; 
> > > > 
> > > > : leapYear? ( year - flag ) 
> > > >     dup >r 400 mod 0=  r@ 100 mod 0<> or  r> 4 mod 0= and ; 
> > > > 
> > > > : <dow> ( day month year -- n )                                     \ this was Mark's DOW
> > > >     dup century >r  100 mod year !  1- month !  day ! 
> > > >     r>  year @ dup 4 /  day @ 
> > > >     year @ leapYear? if leap-years else years then month @ + c@ 
> > > >     + + + +  7 mod ; 
> > > > 
> > > > : dow ( month day year -- str )                                     \ this slight upgrade provides a string
> > > >     -rot  swap  rot                 \ day month year
> > > >     <dow> days ;
> > > >     
> > > > : test-dow ( month day year -- )
> > > >     cr ." Mark: "  3dup dow     count type
> > > >     cr ." Hugh: "  day-of-week  count type ;
> > > > ----------------------------------------------------------------------------
> > > > 
> > > > Here is a test:
> > > > 
> > > > 2 28 1900 test-dow 
> > > > Mark: Tuesday
> > > > Hugh: Wednesday ok
> > > > 3 1 1900 test-dow 
> > > > Mark: Thursday
> > > > Hugh: Thursday ok
> > > > 
> > > > You are assuming that 1900 was a leap year --- it isn't.
> > > > 
> > > > Here, once again for reference, is my code for testing if a year has an extra day or not:
> > > > 
> > > > : extra-day { year -- 1|0 }             \ how many extra days February gets for this year
> > > >     year 4 mod if       0 exit then
> > > >     year 100 mod if     1 exit then
> > > >     year 400 mod if     0 exit then
> > > >     1 ;
> > > > 
> > > > Here is a test:
> > > > 
> > > > 1900 extra-day . 0  ok
> > > 
> > > The problem isn't the leap year calculation. Try my leap year code above:
> > > 
> > > 1900 leapyear? .
> > > 0 ok
> > > 
> > > See? It's (correctly) not a leap.
> > > 
> > > The problem (discovered by you) is the algorithm itself as published on
> > > 
> > > http://www.stoimen.com/blog/2012/04/24/computer-algorithms-how-to-determine-the-day-of-the-week/ 
> > > 
> > > It says to use the *last two digits of the year*, so I faithfully passed in
> > > year mod 100. That results in leapYear? receiving 0 (obviously) which is nonsense year.
> > > 
> > > I'll modify the code.
> > > 
> > > It does make one wonder about the quality of some of these descriptions on
> > > the web.
> > 
> > Yes. It is a mistake for people to find algorithms and implement them without understanding how they work. The guy who said to use the "last two digits of the year" most likely found the algorithm in a math book and then posted it on the internet without understanding it, and with minimal testing.
> > 
> > Now I'm interested in the subject. :-) 
> > I'll think on your algorithm and try to figure it out. I'll also write my own code for Zeller's Algorithm and try to figure it out too. It is possible that the mathisfun guys messed up the implementation, but the algorithm actually works. They didn't provide source-code, or explain the algorithm. I don't know how math can be fun if you aren't figuring things out --- using code, or an algorithm, without understanding it is something that a trained monkey could do.
> > 
> > My own algorithm was just brute-force. I have to loop through the years calling EXTRA-DAY each time until I get to a known year: FIRST-YEAR. This is only realistic with a computer --- nobody would take the time to do this by hand.
> > 
> > On a related note, check this out: http://www.moonstick.com/
> > 
> > Also, I have a book on how to build a sundial. There are actually multiple ways to do this. That is another interesting math problem. Building those things could be an interesting hobby. Put one in your front yard! In my hometown I saw people put old tires painted white and filled with soil in their front yard, then grow flowers there --- a sundial would be somewhat less tacky. ;-)
> > 
> > Keeping track of time is assumed to be the first math problem humans worked on. People had learned arithmetic already, which they used for financial transactions (this is why all the hieroglyphs in English involve money: $ % # etc.). The first actual math involved time though. Also, this is why the five-pointed star is an ancient symbol for religion/science. This is the path that the planet Venus follows along the horizon over a period of about 40 years (the time needed for the orbits of Earth and Venus to synchronize). Venus can be seen with the naked eye. It is possible to build an observatory with stone-age tools that tracks the location of Venus in the sky.
> 
> Bruce Fox and I have been playing with this.
> 
> This is the shortest we came up with:
> 
> 0 value day   0 value month   0 value year
> : dow ( d m y )
>     to year  to month  to day 
>     month 2- 12 / year + to year
>     month month 2- 12 / 12 * - to month
>     month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -  
>     year 400 / +  1+  7 mod  case 
>     0 of ." Sunday " endof     1 of ." Monday " endof
>     2 of ." Tuesday " endof    3 of ." Wednesday " endof
>     4 of ." Thursday " endof   5 of ." Friday " endof
>     6 of ." Saturday " endof
>     endcase ;

If anyone is feeling masochistic, re-write the above such that it uses the
stack only. No variables or values.

[toc] | [prev] | [next] | [standalone]


#56244

FromHowerd <howerdo@yahoo.co.uk>
Date2017-03-24 14:43 -0700
Message-ID<a1b66932-235d-42c8-a12d-f4b945cae435@googlegroups.com>
In reply to#56242
On Friday, 24 March 2017 21:17:32 UTC+1, Mark Wills  wrote:
[snip]
> > 
> > Bruce Fox and I have been playing with this.
> > 
> > This is the shortest we came up with:
> > 
> > 0 value day   0 value month   0 value year
> > : dow ( d m y )
> >     to year  to month  to day 
> >     month 2- 12 / year + to year
> >     month month 2- 12 / 12 * - to month
> >     month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -  
> >     year 400 / +  1+  7 mod  case 
> >     0 of ." Sunday " endof     1 of ." Monday " endof
> >     2 of ." Tuesday " endof    3 of ." Wednesday " endof
> >     4 of ." Thursday " endof   5 of ." Friday " endof
> >     6 of ." Saturday " endof
> >     endcase ;
> 
> If anyone is feeling masochistic, re-write the above such that it uses the
> stack only. No variables or values.

Hi Mark,

Here is something I cobbled together, edited from the SwiftForth calendar.f words.
I hope Elizabeth and Leon don't mind me posting it - I think it is so elegant.

Very similar code has been in Forth, Inc. products for a very long time, 
and I don't think you can get any better than this version of dayOfWeek.
I remember first seeing this in the early 1980's IIRC.

No variables, locals or values. I even removed a constant from the original too.

I'm getting a strange sense of deja vu - haven't we discussed this before on clf?

Best regards,
Howerd

decimal

create DAYS   -1 ,  0 ,  31 ,  59 ,  90 ,  120 ,  151 ,
   181 ,  212 ,  243 ,  273 ,  304 ,  334 ,  367 ,

: @MTH ( u1 -- u2)   CELLS DAYS + @ ;

: D-M-Y ( day month year -- u)   >R  @MTH
   58 OVER < IF  R@ 3 AND 0= - THEN + 1-
   R> 1900 -  [ 365 4 * 1+  ] LITERAL  UM*  4 UM/MOD SWAP 0<> - + ;

: (DD-MMM-YYYY) ( u1 -- c-addr u2)   BASE @ >R  DECIMAL  Y-DD
   ROT 0 <#  # # # #  2DROP  [CHAR] _ HOLD  DM 3 *
   C" JanFebMarAprMayJunJulAugSepOctNovDec" +
   3 0 DO  DUP C@ HOLD 1-  LOOP DROP  [CHAR] _ HOLD
   0 # #  #>  R> BASE ! ;

: .DD-MMM-YYYY ( u -- )   (DD-MMM-YYYY) TYPE SPACE ;

: dayOfWeek ( day month year -- dayOfWeek )   D-M-Y 7 mod ;

\ create dayNames  ," SunMonTueWedThuFriSat"
: .dayOfWeek ( c -- )   3 * s" SunMonTueWedThuFriSat" drop + 3 type space ;

: tt1 ( -- )   cr ." 07 10 1954 was a "  07 10 1954 dayOfWeek dup .dayOfWeek 
   4 = if  ."   passed"  else  ."   failed!!!"  then ;

: tt2 ( -- )   cr ." 10 days later "  07 10 1954 D-M-Y 10 + dup .DD-MMM-YYYY  ." was a " 7 mod .dayOfWeek ;

tt1  tt2

[toc] | [prev] | [next] | [standalone]


#56246

FromMark Wills <markwills1970@gmail.com>
Date2017-03-24 15:36 -0700
Message-ID<1a42cc4e-e40f-49b2-81ba-38d6ca3d4552@googlegroups.com>
In reply to#56244
This is nice. Thanks for posting. 

[toc] | [prev] | [next] | [standalone]


#56260

Fromhughaguilar96@gmail.com
Date2017-03-24 23:47 -0700
Message-ID<baa7f39c-8977-4e98-9a01-0b39e43054b6@googlegroups.com>
In reply to#56244
On Friday, March 24, 2017 at 2:43:19 PM UTC-7, Howerd wrote:
> On Friday, 24 March 2017 21:17:32 UTC+1, Mark Wills  wrote:
> [snip]
> > > 
> > > Bruce Fox and I have been playing with this.
> > > 
> > > This is the shortest we came up with:
> > > 
> > > 0 value day   0 value month   0 value year
> > > : dow ( d m y )
> > >     to year  to month  to day 
> > >     month 2- 12 / year + to year
> > >     month month 2- 12 / 12 * - to month
> > >     month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -  
> > >     year 400 / +  1+  7 mod  case 
> > >     0 of ." Sunday " endof     1 of ." Monday " endof
> > >     2 of ." Tuesday " endof    3 of ." Wednesday " endof
> > >     4 of ." Thursday " endof   5 of ." Friday " endof
> > >     6 of ." Saturday " endof
> > >     endcase ;
> > 
> > If anyone is feeling masochistic, re-write the above such that it uses the
> > stack only. No variables or values.
> 
> Hi Mark,
> 
> Here is something I cobbled together, edited from the SwiftForth calendar.f words.
> I hope Elizabeth and Leon don't mind me posting it - I think it is so elegant.
> 
> Very similar code has been in Forth, Inc. products for a very long time, 
> and I don't think you can get any better than this version of dayOfWeek.
> I remember first seeing this in the early 1980's IIRC.
> 
> No variables, locals or values. I even removed a constant from the original too.
> 
> I'm getting a strange sense of deja vu - haven't we discussed this before on clf?
> 
> Best regards,
> Howerd
> 
> decimal
> 
> create DAYS   -1 ,  0 ,  31 ,  59 ,  90 ,  120 ,  151 ,
>    181 ,  212 ,  243 ,  273 ,  304 ,  334 ,  367 ,
> 
> : @MTH ( u1 -- u2)   CELLS DAYS + @ ;
> 
> : D-M-Y ( day month year -- u)   >R  @MTH
>    58 OVER < IF  R@ 3 AND 0= - THEN + 1-
>    R> 1900 -  [ 365 4 * 1+  ] LITERAL  UM*  4 UM/MOD SWAP 0<> - + ;
> 
> : (DD-MMM-YYYY) ( u1 -- c-addr u2)   BASE @ >R  DECIMAL  Y-DD
>    ROT 0 <#  # # # #  2DROP  [CHAR] _ HOLD  DM 3 *
>    C" JanFebMarAprMayJunJulAugSepOctNovDec" +
>    3 0 DO  DUP C@ HOLD 1-  LOOP DROP  [CHAR] _ HOLD
>    0 # #  #>  R> BASE ! ;
> 
> : .DD-MMM-YYYY ( u -- )   (DD-MMM-YYYY) TYPE SPACE ;
> 
> : dayOfWeek ( day month year -- dayOfWeek )   D-M-Y 7 mod ;
> 
> \ create dayNames  ," SunMonTueWedThuFriSat"
> : .dayOfWeek ( c -- )   3 * s" SunMonTueWedThuFriSat" drop + 3 type space ;
> 
> : tt1 ( -- )   cr ." 07 10 1954 was a "  07 10 1954 dayOfWeek dup .dayOfWeek 
>    4 = if  ."   passed"  else  ."   failed!!!"  then ;
> 
> : tt2 ( -- )   cr ." 10 days later "  07 10 1954 D-M-Y 10 + dup .DD-MMM-YYYY  ." was a " 7 mod .dayOfWeek ;
> 
> tt1  tt2

That doesn't compile. You didn't include Y-DD --- that is as far as I got --- I don't know if anything else is missing.

dayOfWeek is not built into SwiftForth, and I looked in tools-packages and didn't find it there either.

[toc] | [prev] | [next] | [standalone]


#56269

FromJulian Fondren <julian.fondren@gmail.com>
Date2017-03-25 03:00 -0700
Message-ID<e31190b3-1e10-470d-b818-05e4eff6f952@googlegroups.com>
In reply to#56242
On Friday, March 24, 2017 at 3:17:32 PM UTC-5, Mark Wills wrote:
> > Bruce Fox and I have been playing with this.
> > 
> > This is the shortest we came up with:
> > 
> > 0 value day   0 value month   0 value year
> > : dow ( d m y )
> >     to year  to month  to day 
> >     month 2- 12 / year + to year
> >     month month 2- 12 / 12 * - to month
> >     month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -  
> >     year 400 / +  1+  7 mod  case 
> >     0 of ." Sunday " endof     1 of ." Monday " endof
> >     2 of ." Tuesday " endof    3 of ." Wednesday " endof
> >     4 of ." Thursday " endof   5 of ." Friday " endof
> >     6 of ." Saturday " endof
> >     endcase ;
> 
> If anyone is feeling masochistic, re-write the above such that it uses the
> stack only. No variables or values.

  : dow ( d m y -- )
    over 2 - 12 / +
    swap dup 2 - 12 / 12 * - swap
    dup 4 / over 100 / - over 400 / + 1+ +
    -rot dup 1+ 6 * 10 / -rot 2* + + + 7 mod case
      0 of ." Sunday " endof     1 of ." Monday " endof
      2 of ." Tuesday " endof    3 of ." Wednesday " endof
      4 of ." Thursday " endof   5 of ." Friday " endof
      6 of ." Saturday " endof
      endcase ; 

technique: the stack comment is the same at the end of
the first three lines. So it's easy to remember.

[toc] | [prev] | [next] | [standalone]


#56279

From"Wolfgang Allinger" <all2001@spambog.com>
Date2017-03-25 09:06 -0300
Message-ID<DyZtz1aUQoB@allinger-307049.user.uni-berlin>
In reply to#56242
 On 24 Mar 17 at group /comp/lang/forth in article 8032bba9-fb6d-4084-b730-c76381b3b8e0@googlegroups.com
 <markwills1970@gmail.com>  (Mark Wills)  wrote:

>> This is the shortest we came up with:
>>
>> 0 value day   0 value month   0 value year
>> : dow ( d m y )
>>     to year  to month  to day
>>     month 2- 12 / year + to year
>>     month month 2- 12 / 12 * - to month
>>     month 2* day +  month 1+ 6 * 10 / +  year +  year 4 / +  year 100 / -
>>     year 400 / +  1+  7 mod  case
>>     0 of ." Sunday " endof     1 of ." Monday " endof
>>     2 of ." Tuesday " endof    3 of ." Wednesday " endof
>>     4 of ." Thursday " endof   5 of ." Friday " endof
>>     6 of ." Saturday " endof
>>     endcase ;

> If anyone is feeling masochistic, re-write the above such that it uses the
> stack only. No variables or values.

See my example of 22.3.2017

MID: DyNsoReEQoB@allinger-307049.user.uni-berlin

However I'm not shure the calculation for J and K is ok.
Maybe need an 1- for J.

It's much shorter, stack only, no IF...


Saludos (an alle Vernünftigen, Rest sh. sig)
Wolfgang

-- 
Ich bin in Paraguay lebender Trollallergiker :) reply Adresse gesetzt!
Ich diskutiere zukünftig weniger mit Idioten, denn sie ziehen mich auf
ihr Niveau herunter und schlagen mich dort mit ihrer Erfahrung! :p
(lt. alter usenet Weisheit)      iPod, iPhone, iPad, iTunes, iRak, iDiot

[toc] | [prev] | [next] | [standalone]


#56239

FromMark Wills <markwills1970@gmail.com>
Date2017-03-24 12:28 -0700
Message-ID<f118bbd3-780f-4dcc-a6df-7c3a5670a216@googlegroups.com>
In reply to#56231
On Friday, 24 March 2017 17:24:26 UTC, hughag...@gmail.com  wrote:
> On Friday, March 24, 2017 at 9:39:00 AM UTC-7, Mark Wills wrote:
> > On Thursday, 23 March 2017 22:23:32 UTC, hughag...@gmail.com  wrote:
> > > On Thursday, March 23, 2017 at 5:35:46 AM UTC-7, Mark Wills wrote:
> > > > On Thursday, 23 March 2017 02:16:27 UTC, hughag...@gmail.com  wrote:
> > > > > I glanced over your code and I was totally confused --- I don't know what you are doing --- I don't think that works.
> > > > 
> > > > It does work. It has had a fairly robust testing.
> > > > 
> > > > Here's the source where I got the explanation and the algorithm:
> > > > 
> > > > http://www.stoimen.com/blog/2012/04/24/computer-algorithms-how-to-determine-the-day-of-the-week/
> > > 
> > > I didn't get my algorithm from anywhere. I just figured it out myself. I won't say that I never make mistakes --- but it is very rare --- this is not an example of me making a mistake.
> > > 
> > > I don't know if you are using Zeller's Algorithm or not. I haven't really looked at your code, the website you referenced, or Zeller's Algorithm very closely. 
> > > 
> > > Here is your code slightly upgraded for testing purposes:
> > > ----------------------------------------------------------------------------
> > > variable year 
> > > variable month 
> > > variable day 
> > > 
> > > create years 0 c, 3 c, 3 c, 6 c, 1 c, 4 c, 6 c, 2 c, 5 c, 0 c, 3 c, 5 c, 
> > > create leap-years 6 c, 2 c, 3 c, 6 c, 1 c, 4 c, 6 c, 2 c, 5 c, 0 c, 3 c, 5 c, 
> > > create centuries 4 c, 2 c, 0 c, 6 c, 
> > > 
> > > : century ( year - n ) 
> > >     1700 /mod drop 100 / 4 mod centuries + c@ ; 
> > > 
> > > : leapYear? ( year - flag ) 
> > >     dup >r 400 mod 0=  r@ 100 mod 0<> or  r> 4 mod 0= and ; 
> > > 
> > > : <dow> ( day month year -- n )                                     \ this was Mark's DOW
> > >     dup century >r  100 mod year !  1- month !  day ! 
> > >     r>  year @ dup 4 /  day @ 
> > >     year @ leapYear? if leap-years else years then month @ + c@ 
> > >     + + + +  7 mod ; 
> > > 
> > > : dow ( month day year -- str )                                     \ this slight upgrade provides a string
> > >     -rot  swap  rot                 \ day month year
> > >     <dow> days ;
> > >     
> > > : test-dow ( month day year -- )
> > >     cr ." Mark: "  3dup dow     count type
> > >     cr ." Hugh: "  day-of-week  count type ;
> > > ----------------------------------------------------------------------------
> > > 
> > > Here is a test:
> > > 
> > > 2 28 1900 test-dow 
> > > Mark: Tuesday
> > > Hugh: Wednesday ok
> > > 3 1 1900 test-dow 
> > > Mark: Thursday
> > > Hugh: Thursday ok
> > > 
> > > You are assuming that 1900 was a leap year --- it isn't.
> > > 
> > > Here, once again for reference, is my code for testing if a year has an extra day or not:
> > > 
> > > : extra-day { year -- 1|0 }             \ how many extra days February gets for this year
> > >     year 4 mod if       0 exit then
> > >     year 100 mod if     1 exit then
> > >     year 400 mod if     0 exit then
> > >     1 ;
> > > 
> > > Here is a test:
> > > 
> > > 1900 extra-day . 0  ok
> > 
> > The problem isn't the leap year calculation. Try my leap year code above:
> > 
> > 1900 leapyear? .
> > 0 ok
> > 
> > See? It's (correctly) not a leap.
> > 
> > The problem (discovered by you) is the algorithm itself as published on
> > 
> > http://www.stoimen.com/blog/2012/04/24/computer-algorithms-how-to-determine-the-day-of-the-week/ 
> > 
> > It says to use the *last two digits of the year*, so I faithfully passed in
> > year mod 100. That results in leapYear? receiving 0 (obviously) which is nonsense year.
> > 
> > I'll modify the code.
> > 
> > It does make one wonder about the quality of some of these descriptions on
> > the web.
> 
> Yes. It is a mistake for people to find algorithms and implement them without understanding how they work. The guy who said to use the "last two digits of the year" most likely found the algorithm in a math book and then posted it on the internet without understanding it, and with minimal testing.
> 
> Now I'm interested in the subject. :-) 
> I'll think on your algorithm and try to figure it out. I'll also write my own code for Zeller's Algorithm and try to figure it out too. It is possible that the mathisfun guys messed up the implementation, but the algorithm actually works. They didn't provide source-code, or explain the algorithm. I don't know how math can be fun if you aren't figuring things out --- using code, or an algorithm, without understanding it is something that a trained monkey could do.
> 
> My own algorithm was just brute-force. I have to loop through the years calling EXTRA-DAY each time until I get to a known year: FIRST-YEAR. This is only realistic with a computer --- nobody would take the time to do this by hand.
> 
> On a related note, check this out: http://www.moonstick.com/
> 
> Also, I have a book on how to build a sundial. There are actually multiple ways to do this. That is another interesting math problem. Building those things could be an interesting hobby. Put one in your front yard! In my hometown I saw people put old tires painted white and filled with soil in their front yard, then grow flowers there --- a sundial would be somewhat less tacky. ;-)
> 
> Keeping track of time is assumed to be the first math problem humans worked on. People had learned arithmetic already, which they used for financial transactions (this is why all the hieroglyphs in English involve money: $ % # etc.). The first actual math involved time though. Also, this is why the five-pointed star is an ancient symbol for religion/science. This is the path that the planet Venus follows along the horizon over a period of about 40 years (the time needed for the orbits of Earth and Venus to synchronize). Venus can be seen with the naked eye. It is possible to build an observatory with stone-age tools that tracks the location of Venus in the sky.

I'd quite to like to look at adding and subtracting dates, though I've never
looked at these before. I've always used (in Microsoft langauges) the
built-in functions which all work perfectly.

I *think* the majority of these routines work by converting a given date
and time into milliseconds (normally from 1/1/1970) and projecting that
along a calendar to see which day it lands on. I'd have to have a look on
the web for some example algorithms.

It would be VERY cool if one could say (in Forth):

1 Dec 1970  10 days+ .date

And it says 11/12/1970

Or 12 Aug 1989 3 months- 4 days+ .date

Or 12 Aug 1989  12 Aug 1990 datediff .

And it says 365 (days) or whatever.

If one calculates everything in milliseconds it becomes possible to 
add/subtract dates with times quite easily.

Yes. A Forth time and date library would be marvelous.

[toc] | [prev] | [next] | [standalone]


#56240

FromJulian Fondren <julian.fondren@gmail.com>
Date2017-03-24 12:49 -0700
Message-ID<7af93a56-fd51-4729-b251-46d7b929a78f@googlegroups.com>
In reply to#56239
On Friday, March 24, 2017 at 2:28:12 PM UTC-5, Mark Wills wrote:
> Yes. A Forth time and date library would be marvelous.

FFL has a few date-related modules:

https://github.com/uho/ffl/blob/master/ffl/dos.fs
https://github.com/uho/ffl/blob/master/ffl/dti.fs
https://github.com/uho/ffl/blob/master/ffl/dtm.fs

A good reference on the kind of capabilities and API that people would
like can be found here: http://momentjs.com/guides/ . Of course it
doesn't have to look exactly like that in Forth. Forth is more
flexible, so it should look much nicer than that :-)

As it is, if the UI will be in a browser, you can often get away with
keeping time as seconds-since-the-epoch and then letting JavaScript
display that as "22 minutes ago" or whatever's appropriate.

[toc] | [prev] | [next] | [standalone]


#56241

FromMark Wills <markwills1970@gmail.com>
Date2017-03-24 13:15 -0700
Message-ID<fb27e9e9-0057-4105-81b9-a2bf3f97bd71@googlegroups.com>
In reply to#56240
On Friday, 24 March 2017 19:49:29 UTC, Julian Fondren  wrote:
> On Friday, March 24, 2017 at 2:28:12 PM UTC-5, Mark Wills wrote:
> > Yes. A Forth time and date library would be marvelous.
> 
> FFL has a few date-related modules:
> 
> https://github.com/uho/ffl/blob/master/ffl/dos.fs
> https://github.com/uho/ffl/blob/master/ffl/dti.fs
> https://github.com/uho/ffl/blob/master/ffl/dtm.fs
> 
> A good reference on the kind of capabilities and API that people would
> like can be found here: http://momentjs.com/guides/ . Of course it
> doesn't have to look exactly like that in Forth. Forth is more
> flexible, so it should look much nicer than that :-)
> 
> As it is, if the UI will be in a browser, you can often get away with
> keeping time as seconds-since-the-epoch and then letting JavaScript
> display that as "22 minutes ago" or whatever's appropriate.

Thanks for this. There's some lovely code in there. I think I'll be studying
this for the next few days.

[toc] | [prev] | [next] | [standalone]


#56355

Fromhughaguilar96@gmail.com
Date2017-03-26 14:49 -0700
Message-ID<69ccd699-84a7-419c-b13e-95eb5ea26efe@googlegroups.com>
In reply to#56231
On Friday, March 24, 2017 at 10:24:26 AM UTC-7, hughag...@gmail.com wrote:
> Now I'm interested in the subject. :-) 
> I'll think on your algorithm and try to figure it out. I'll also write my own code for Zeller's Algorithm and try to figure it out too. It is possible that the mathisfun guys messed up the implementation, but the algorithm actually works. They didn't provide source-code, or explain the algorithm. I don't know how math can be fun if you aren't figuring things out --- using code, or an algorithm, without understanding it is something that a trained monkey could do.

Well, I implemented Zeller's Algorithm and it works --- it agrees with my algorithm for all the tests that I did --- the mathisfun website apparently had a bug in their implementation.

: dow { month day year | K J -- str }
    month 3 < if  12 +to month  -1 +to year  then
    year 100 /mod  to J  to K
    month 1 +  13 *  5 /    
    day +                   
    K +                     
    K 4 / +                 
    J 4 / +                 
    J 5 * +                 
    1 -  7 mod  days ;
    
: test-dow ( month day week -- )    
    cr ." Hugh:   "  3dup day-of-week  count type
    cr ." Zeller: "  dow  count type ;

I still haven't figured out how it works --- I just typed it in like a trained monkey --- note, btw, that the Wikipedia page formula, if typed in directly, doesn't work.

> My own algorithm was just brute-force. I have to loop through the years calling EXTRA-DAY each time until I get to a known year: FIRST-YEAR. This is only realistic with a computer --- nobody would take the time to do this by hand.

I still like my own algorithm better than Zeller's Algorithm. Mine checks the validity of the date given to it and aborts with a helpful error message if it is invalid. DOW just returns an invalid result.

[toc] | [prev] | [next] | [standalone]


Page 2 of 3 — ← Prev page 1 [2] 3  Next page →

Back to top | Article view | comp.lang.forth


csiph-web