- Start Date: Sat Jan 01 16:37:58 CST 2000
- End Date: Wed Dec 31 16:37:58 CST 2008
- Number of weekends: 939
Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
Forum Search
Forum Statistics
UsersTotal Post History
- Posts:
- 78544
- Topics:
- 17949
7-Day Post History
- New Posts:
- 48
- New Topics:
- 22
- Active Topics:
- 26
Our newest member
Other
-
FAQ
All times are UTC [ DST ]
Google Ads
LTD Puzzle 10 - Weekends between two dates
Forum rules
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
18 posts • Page 1 of 1
Please wait...
LTD Puzzle 10 - Weekends between two dates
This week's puzzle is a simple one. Write a program that will take two dates as inputs, and output the number of weekends between them.
To be consistent, the ranges will include the start and end dates. And we will count 1/2 weekends.
Have fun!
To be consistent, the ranges will include the start and end dates. And we will count 1/2 weekends.
Have fun!
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
-

AlexCuse - LTD Admin

-










- Posts: 5263
- Joined: Tue Oct 09, 2007 5:26 pm
- Location: Pennsylvania, US
Solution in Java
A solution in java using the existing Calendar class. I have counter Saturday and Sunday as weekends.
And the output is below.
Code is hidden, SHOW
And the output is below.
- shamsm
- Apprentice

-
- Posts: 12
- Joined: Wed Jul 30, 2008 10:09 am
Re: LTD Puzzle 10 - Weekends between two dates
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
-

AlexCuse - LTD Admin

-










- Posts: 5263
- Joined: Tue Oct 09, 2007 5:26 pm
- Location: Pennsylvania, US
-

SQLDenis - LTD Admin

-












- Posts: 21304
- Joined: Wed Oct 10, 2007 6:43 pm
- Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Re: LTD Puzzle 10 - Weekends between two dates
My solution in PHP:
Output (first 14 lines):
edit: change some comments, you know - english...
Code is hidden, SHOW
Output (first 14 lines):
- From 20080811 to 20080811 are 0 weekends. |11|
- From 20080811 to 20080812 are 0 weekends. |11|12|
- From 20080811 to 20080813 are 0 weekends. |11|12|13|
- From 20080811 to 20080814 are 0 weekends. |11|12|13|14|
- From 20080811 to 20080815 are 0 weekends. |11|12|13|14|15|
- From 20080811 to 20080816 are 0.5 weekends. |11|12|13|14|15|16|
- From 20080811 to 20080817 are 1 weekends. |11|12|13|14|15|16|17|
- From 20080811 to 20080818 are 1 weekends. |11|12|13|14|15|16|17|18|
- From 20080811 to 20080819 are 1 weekends. |11|12|13|14|15|16|17|18|19|
- From 20080811 to 20080820 are 1 weekends. |11|12|13|14|15|16|17|18|19|20|
- From 20080811 to 20080821 are 1 weekends. |11|12|13|14|15|16|17|18|19|20|21|
- From 20080811 to 20080822 are 1 weekends. |11|12|13|14|15|16|17|18|19|20|21|22|
- From 20080811 to 20080823 are 1.5 weekends. |11|12|13|14|15|16|17|18|19|20|21|22|23|
- From 20080811 to 20080824 are 2 weekends. |11|12|13|14|15|16|17|18|19|20|21|22|23|24|
edit: change some comments, you know - english...
I try to improve my English language skills. Most things i do better than this.
- tisodotsk
- Apprentice

-

- Posts: 22
- Joined: Fri Aug 08, 2008 12:45 pm
- Location: Bratislava, Slovakia
-

Remou - LTD Admin

-










- Posts: 5115
- Joined: Sun Oct 14, 2007 11:26 am
Re: LTD Puzzle 10 - Weekends between two dates
Remou, its too simple. What's the fun in that 

Say what you like about the tenets of National Socialism Dude, at least it's an ethos
-

AlexCuse - LTD Admin

-










- Posts: 5263
- Joined: Tue Oct 09, 2007 5:26 pm
- Location: Pennsylvania, US
Re: LTD Puzzle 10 - Weekends between two dates
Remou's doesn't take into account the partial weekends.
e.g. Sunday to Saturday - two week span - the answer should be 2 (.5 for Sunday, 1 for the middle weekend and .5 for the concluding Saturday) - code returns 3
Sunday to Saturday single week similarly returns 2 when the answer should be 1.
I had virtually identical code started using mod 7 and number of days, but didn't get around to finishing it because I ran into the same problems (and didn't take the time to correct).
e.g. Sunday to Saturday - two week span - the answer should be 2 (.5 for Sunday, 1 for the middle weekend and .5 for the concluding Saturday) - code returns 3
- ?Retwe(#3-2-2008#, #3-15-2008#)
- 3
Sunday to Saturday single week similarly returns 2 when the answer should be 1.
- ?Retwe(#3-2-2008#, #3-8-2008#)
- 2
I had virtually identical code started using mod 7 and number of days, but didn't get around to finishing it because I ran into the same problems (and didn't take the time to correct).

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
-

traingamer - Senior Sage

-




- Posts: 1480
- Joined: Thu Feb 28, 2008 4:13 pm
- Location: St. Louis, MO, US
Re: LTD Puzzle 10 - Weekends between two dates
I interpreted
To mean that partial weekends counted as 1, therefore .5,1,.5 would equal three, not 2. Similarly, Sunday to Saturday is .5,.5 and by those rules equals 2. That is, the range encompasses two weekends.
Have I misinterpreted the rules?
To be consistent, the ranges will include the start and end dates. And we will count 1/2 weekends.
To mean that partial weekends counted as 1, therefore .5,1,.5 would equal three, not 2. Similarly, Sunday to Saturday is .5,.5 and by those rules equals 2. That is, the range encompasses two weekends.
Have I misinterpreted the rules?
x
-

Remou - LTD Admin

-










- Posts: 5115
- Joined: Sun Oct 14, 2007 11:26 am
Re: LTD Puzzle 10 - Weekends between two dates
Remou wrote:Have I misinterpreted the rules?
Maybe I did.

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
-

traingamer - Senior Sage

-




- Posts: 1480
- Joined: Thu Feb 28, 2008 4:13 pm
- Location: St. Louis, MO, US
Re: LTD Puzzle 10 - Weekends between two dates
I guess that is less than clear. I meant we would count 1/2 weekend as 1/2, but did leave some room for interpretation.
I collapsed under the pressure of delivering the great one's message.
I collapsed under the pressure of delivering the great one's message.
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
-

AlexCuse - LTD Admin

-










- Posts: 5263
- Joined: Tue Oct 09, 2007 5:26 pm
- Location: Pennsylvania, US
Re: LTD Puzzle 10 - Weekends between two dates
I gave it up after a short while because I just don't have the time. But if I had interpreted it that 1/2 weekends would be 0.5 instead of 1 each, I think I would have finished! 

God cries a little bit every time someone builds a database.
-

Emtucifor - Guru

-










- Posts: 2832
- Joined: Fri May 30, 2008 9:30 pm
- Location: California
Re: LTD Puzzle 10 - Weekends between two dates
I interpreted it as 1/2 + 1 + 1/2 = 2
-

SQLDenis - LTD Admin

-












- Posts: 21304
- Joined: Wed Oct 10, 2007 6:43 pm
- Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Re: LTD Puzzle 10 - Weekends between two dates
that's what I intended Denis. Sorry for any confusion.
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
-

AlexCuse - LTD Admin

-










- Posts: 5263
- Joined: Tue Oct 09, 2007 5:26 pm
- Location: Pennsylvania, US
Re: LTD Puzzle 10 - Weekends between two dates
And 1 + 1/2 = 1.5?
God cries a little bit every time someone builds a database.
-

Emtucifor - Guru

-










- Posts: 2832
- Joined: Fri May 30, 2008 9:30 pm
- Location: California
Re: LTD Puzzle 10 - Weekends between two dates
mmmm, now my code is incorrect
SET @s = '20080816';
SET @e = '20080823';
should give 1.5
Now I don't remember what I understood when I did this, I made it match whatever the person before me had
SET @s = '20080816';
SET @e = '20080823';
should give 1.5
Now I don't remember what I understood when I did this, I made it match whatever the person before me had
-

SQLDenis - LTD Admin

-












- Posts: 21304
- Joined: Wed Oct 10, 2007 6:43 pm
- Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Re: LTD Puzzle 10 - Weekends between two dates
Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
-

traingamer - Senior Sage

-




- Posts: 1480
- Joined: Thu Feb 28, 2008 4:13 pm
- Location: St. Louis, MO, US
Re: LTD Puzzle 10 - Weekends between two dates
The winners have been determined!
Peoples Champ: shamsm
LTD Admins Champion - traingamer.
Congratulations!
Peoples Champ: shamsm
LTD Admins Champion - traingamer.
Congratulations!
pink fuzzy slippers
-

chrissie1 - Senior Guru

-











- Posts: 9106
- Joined: Wed Oct 10, 2007 7:18 pm
- Location: Belgium
18 posts • Page 1 of 1


LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.