Author Topic: -={ Challenge }=- Doomsday Algorithm  (Read 12943 times)

0 Members and 1 Guest are viewing this topic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #15 on: May 11, 2012, 09:49:11 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun ee_getday (y m d / a)
  2.   (setq y (- y (setq a (/ (- 14 m) 12))))
  3.   (nth (rem (+ d y (/ y 4) (/ y -100) (/ y 400) (/ (* 31 (+ m (* 12 a) -2)) 12)) 7)
  4.        '("Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday")
  5.   )
  6. )

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #16 on: May 11, 2012, 09:54:59 AM »
 8-)

Code: [Select]
_$ (keith_doomsday 1812 2 20)
"Thursday"
_$ (pBe_getday 1812 2 20)
"Thursday"
_$ (lm:getday 1812 2 20)
"Thursday"
_$ (ee_getday 1812 2 20)
"Thursday"

Code - Auto/Visual Lisp: [Select]
  1. Benchmarking ..................Elapsed milliseconds / relative speed for 32768 iteration(s):
  2.  
  3.     (EE_GETDAY 1812 2 20)..........1155 / 2.88 <fastest>
  4.     (LM:GETDAY 1812 2 20)..........1170 / 2.84
  5.     (KEITH_DOOMSDAY 1812 2 20).....1248 / 2.66
  6.     (PBE_GETDAY 1812 2 20).........3323 / 1 <slowest>

It wouldn't be right if Evgeniy wasn't at the top :lol:

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #17 on: May 11, 2012, 10:08:10 AM »
Code - Auto/Visual Lisp: [Select]
  1. _$
  2. Benchmarking ...................Elapsed milliseconds / relative speed for 65536 iteration(s):
  3.  
  4.     (LEE_GETDAY 2012 5 11).....1513 / 1 <fastest>
  5.     (EE_GETDAY 2012 5 11)......1513 / 1 <slowest>
  6.  
  7.  
  8. _$
:-)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #18 on: May 11, 2012, 10:17:00 AM »
It wouldn't be right if Evgeniy wasn't at the top :lol:

Why?   8-)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #19 on: May 11, 2012, 10:24:42 AM »
It wouldn't be right if Evgeniy wasn't at the top :lol:

Why?   8-)

Because we measure the awesomeness of our codes on a scale from 0 to Evgeniy  8-)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #20 on: May 11, 2012, 10:45:26 AM »
Now, my code was very similar to yours!  :-D

LE3

  • Guest
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #21 on: May 11, 2012, 12:24:29 PM »
after to much lurking... here is something extracted from one of my old classes arxKey - just to put a little pepper on the lisp salad.-
Code - C++: [Select]
  1. // returns same left value as:
  2. // acedGetVar(_T("DATE"), &rb)
  3. // acdbRToS(r, 2, 12, fmtval);
  4. long JulianDayNumber (int y, int m, int d)
  5. {
  6.         if (m < 3) { y--; m += 12; }
  7.         y += 8000;
  8.         return (y * 365) + (y / 4) - (y / 100) + (y / 400) + (m * 153 + 3) / 5 - 92 + d - 1 - 1200820;
  9. }
  10. [code]
  11. [code=cpp]
  12. static void LESQ_TST(void)
  13. {
  14.         //long val = JulianDayNumber(2012, 5, 11);
  15.         long val = JulianDayNumber(1812, 2, 20);
  16.         int dayOfWeek = val % 7 + 1;
  17.         AcString day;
  18.         switch (dayOfWeek)
  19.         {
  20.         case 1: day = _T("Monday"); break;
  21.         case 2: day = _T("Tuesday"); break;
  22.         case 3: day = _T("Wendsday"); break;
  23.         case 4: day = _T("Thursday"); break;
  24.         case 5: day = _T("Friday"); break;
  25.         case 6: day = _T("Saturday"); break;
  26.         case 7: day = _T("Sunday"); break;
  27.         }
  28.         acutPrintf (_T("\nDay of the week[%s] \n"), day.kACharPtr());
  29. }
  30.  

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #22 on: May 11, 2012, 12:34:51 PM »
You know this is so much easier in C++ or C#
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #23 on: May 11, 2012, 05:19:29 PM »
You know this is so much easier in C++ or C#

Indeed, a single line.  :-o

LE3

  • Guest
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #24 on: May 11, 2012, 05:29:15 PM »
^ indeed for many things - but not for everything (at least in c++) - per all the stuff i have done so far..

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #25 on: May 12, 2012, 12:55:02 AM »
I was thinking more on the lines of creating a time struct, passing the date values then outputting the day.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #26 on: May 12, 2012, 03:53:47 AM »
Almost a one-liner :)
« Last Edit: May 12, 2012, 03:56:59 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #27 on: May 12, 2012, 08:21:49 AM »
Very nice Kerry - out of interest, can that method handle dates occurring before 1900 (as per Evgeniy's example), as I know that is a limitation for some systems.

Also, I like your VS colour scheme, though not sure about the 'blue screen of death' style console  :lol:


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #28 on: May 12, 2012, 08:20:53 PM »

Quote
The DateTime value type represents dates and times with values ranging from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.).



Yes, I like that colour Scheme. http://www.theswamp.org/index.php?topic=41700.msg468090#msg468090

The 'Blue Screen' is just me being rebellious :)

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: -={ Challenge }=- Doomsday Algorithm
« Reply #29 on: May 13, 2012, 05:53:12 AM »
Excellent  8-)