Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge: Compute the number of Tuesdays since a given date
#1
Sounds simple, right?
Starting from a given date, no earlier than 1/1/1900 just to avoid calendar change discussions,
compute the number of Tuesdays that have transpired up to but not including today.
Please debug before submitting.
*****
Reply
#2
5393?

Sorry im lazy I did it with a calculator

But didnt give away the answer so that people could make programs to work it out. =P

am I close?
Reply
#3
Quote:...am I close?
What do you mean "am I close"? :o At least pick a date and tell us how many Tuesday's you computed. Actually, the idea is to program a solution.
*****
Reply
#4
Oh sorry, I thought you meant since 1/1/1900

And I did give the answer, its just in very small font before the "?"

Nevermind. :roll:
Reply
#5
Leap years... aso...

Its a mess...


And I think the algo should work on all dates, back to 1/1/1900

For example, you should be able to give a different date, and it should compute it correctly.

25/11/1972 up to today should work too.
Reply
#6
Well, I have a solution, but I'm not going to post it because it uses VBDOS's awesome time/date handling features, and thus wont work on QB 4.5 :S

Oh well.
onathan Simpson
Reply
#7
ZIRE: Right, it has to work for any given (input provided) date starting with 1/1/1900.

DARK_PREVAIL: Put the date of Jan 01, 2004 into your calculator and tell us the answer. We can check this one by hand on a calendar.

JONATHAN: Why don't you do some testing on VBDOS and make sure that the awsome routine really works. Then, we can use your VBDOS program to verify any submitted answers, like the one from Dark_Prevail's calculator.
PS: I have most of the routines already in QuickBASIC, but need to put together a special case to count Tuesdays. So, we have no programmed, trustworthy solution yet.

This is going to be fun!
*****
Reply
#8
I'm sorry Moneo i mess up thursday and tuesday ( :oops: )

But I hope this helps you.

Code:
DEFDBL A-Z
DECLARE FUNCTION JulianDate# (y%, m%, d%, ut%)

a = JulianDate#(1899, 12, 29, -3) '<-- este dia fue viernes
' para contar los martes habria que poner un miercoles
b = JulianDate#(2004, 6, 11, -3) '<-- ajustar fecha
dias = b - a

PRINT "Hoy es ";
SELECT CASE FIX(dias) MOD 7
  CASE 5: PRINT "miercoles"
  CASE 6: PRINT "jueves"
  CASE 0: PRINT "viernes"
  CASE 1: PRINT "sabado"
  CASE 2: PRINT "domingo"
  CASE 3: PRINT "lunes"
  CASE 4: PRINT "martes"
END SELECT

PRINT "Han pasado "; FIX(dias / 7); " jueves"

DEFSNG A-Z
FUNCTION JulianDate# (y%, m%, d%, ut%)
  DIM a#, b#, c#
  a# = FIX(7# * (y% + FIX((m% + 9#) / 12#)) / 4#)
  b# = FIX(3# * (FIX((y% + (m% - 9#) / 7#) / 100#) + 1) / 4#)
  c# = FIX(275 * m% / 9#) + d% + 1721028.5# + ut% / 24#
  JulianDate# = 367# * y% - a# - b# + c#
END FUNCTION

Also take a look at http://scienceworld.wolfram.com/astronom...nDate.html.
Reply
#9
Thanks Xhantt, I'm not sure how to run you program. Why do I need to give it the fourth parameter and why is it negative?

Looks as if you like the FIX command. I've never used it so I have to consult my manual. Must be a variation of the INT command.

In general, your program looks like it's headed in the right direction. Answer my questions and then give me a chance to do some testing. Have you tested it with easy dates so you can check the result on a calendar?

By the way, this program is not just for fun. We have backup tapes that are generated on Tuesday through Saturday over and over again on the same day of the week. We know the date when the first Tuesday thru Saturday tapes were written, but now we need to know how many times each of these tapes were written, because there is a limit as to how many times you can write on them. So, we need to run the algorithm for the Tuesday tape, then the Wednesday tape, etc.
*****
Reply
#10
I dont have the qb help installed, when i type fix i want it to be integer part.

The last parameter is the UT timezone. The Julian date is used in astronomical calculations (astrological also). My function is turning Gregorian date (the one that is used in occident) to Julian date. This dates are universal starting from long time ago.

Given to dates i pass then to julian calendar and the difference is the amount of days elapsed. Whith enough precision you can have the day up to millisecons. Check the page i give for other formulae. Read carefully for understand them.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)