• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Day of week

 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your assignment, should you choose to accept it, is to come up with the Day Of The Week calculation that is easiest to perform mentally. The algorithm has to work for for any date from Jan 1, 1900 to Dec 31, 2099. (Two centuries ought to be enough.) The final result of the calculation must come out so that a 0 represents Sunday, 1 Monday, ... 6 Saturday.


The exact fitness calulation will be this:


As you can see allowance was made for the fact that x mod 4 is easier to calculate in your head than x mod 7.


Let's see an example algorithm/calculation (March 2, 2005)


Can I cut down that 24 points for 12 constants? Hmmm... 5, 1, 1, 4, 6, 2, 4, 0, 3, 5, 1, 3. I don't see anything.

Surely, there is an algorithm that scores fewer than 42 points (and still comes out with the right answer).


Ryan
[ March 02, 2005: Message edited by: Ryan McGuire ]
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ryan McGuire:
Surely, there is an algorithm that scores fewer than 42 points

Forget the algorithm -- you've just found the answer to life, the universe, and everything!
[ March 02, 2005: Message edited by: David Harkness ]
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But it scores < not = 42.

But he is near the answer.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I personally would just type this into the address bar:



Would your algo. account for leap year? To lazy to test!

Eric
 
Ryan McGuire
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eric Pascarello:
I personally would just type this into the address bar:



Would your algo. account for leap year? To lazy to test!

Eric



Very nice if you're near a computer. Notice, however, that I'm going for easy to memorize/perform in one's head. One might infer that I don't plan on running this on a compueter.

The divide by four in the first step is what handles leap years.

Ryan
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I cut down that 24 points for 12 constants? Hmmm... 5, 1, 1, 4, 6, 2, 4, 0, 3, 5, 1, 3. I don't see anything.

Not exactly in the rules, but why not call it 511462403513 (ie one constant ) and define the maths to pop the M'th digit? What are the 'points' costs of abitrary div, mod, power, log functions?

[edit - yeah yeah, i read it a bit closer ]
[ March 05, 2005: Message edited by: David O'Meara ]
 
Ryan McGuire
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ryan McGuire:

...

The exact fitness calulation will be this:
...



2 things:
  • Any MOD operation that's really easy counts the same as a MOD 4. I would say that MOD 2, 4, 5, 10, 20, 40, 50, 100 all fit in this class. Maybe MOD 3 and 30 fit in here too. I'd have to say MOD 7 and 12 don't.
  • What may be obvious is that I'm looking for a DayOfWeek calculation that's easy to do in one's head. The "fitness calculation" score was an attempt to characterize "easy to do in head". If you can make an argument that you've found an improvement that makes the calculation easier despite having a higher score, I'd love to see it.


  • Ryan
     
    Ranch Hand
    Posts: 128
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
     
    Ranch Hand
    Posts: 3852
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Ryan McGuire wrote:Your assignment, should you choose to accept it, is to come up with the Day Of The Week calculation that is easiest to perform mentally. The algorithm has to work for for any date from Jan 1, 1900 to Dec 31, 2099. (Two centuries ought to be enough.) The final result of the calculation must come out so that a 0 represents Sunday, 1 Monday, ... 6 Saturday.


    The exact fitness calulation will be this:


    As you can see allowance was made for the fact that x mod 4 is easier to calculate in your head than x mod 7.


    Let's see an example algorithm/calculation (March 2, 2005)


    Can I cut down that 24 points for 12 constants? Hmmm... 5, 1, 1, 4, 6, 2, 4, 0, 3, 5, 1, 3. I don't see anything.

    Surely, there is an algorithm that scores fewer than 42 points (and still comes out with the right answer).


    Ryan
    [ March 02, 2005: Message edited by: Ryan McGuire ]



    A doubt in 3rd line. 24 points are for remembering 12 constants but adding will also accumulate 3 more points. Right?
     
    ankur rathi
    Ranch Hand
    Posts: 3852
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    March 2, 2005







    Total points = 40, if consider MOD 100 for 2 points.

    No better than yours, this will not work for leap years, this will only work for 21st century (2000s).

    Reference: http://www.terra.es/personal2/grimmer/#Monthcodes
     
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Method to calulate day of week.

    (works for year from 1900) (takes care of leap years)

    Example date: 16-Feb-2009
    ...
    ...

    Edit: The method posted was wrong. Realised the mistake.
     
    Pankaj Rathod
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic