Login or Sign Up to become a member!
LessThanDot Site Logo

LessThanDot

A Technical Community for IT Professionals

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.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

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

Highly Rated Users

Forum
No Posts Rated

Top 50
Given
Received

Forum Statistics

Users
Members:
1575
Members Online:
2
Guests Online:
4

Total Post History
Posts:
80489
Topics:
18432

7-Day Post History
New Posts:
6
New Topics:
2
Active Topics:
5

Our newest member
dhoom

Other

FAQ
All times are UTC [ DST ]

Google Ads

LTD Puzzle 10 - Weekends between two dates

Mind Boggling Puzzles, to keep that grey matter in shape...
Forum rules
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
Please wait...

LTD Puzzle 10 - Weekends between two dates

Postby AlexCuse on Fri Aug 08, 2008 7:19 pm

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!
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021
 
Posts: 5408
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US
Unrated

Solution in Java

Postby shamsm on Mon Aug 11, 2008 10:31 pm

A solution in java using the existing Calendar class. I have counter Saturday and Sunday as weekends.

Code is hidden, SHOW


And the output is below.
  1. Start Date: Sat Jan 01 16:37:58 CST 2000
  2. End Date: Wed Dec 31 16:37:58 CST 2008
  3. Number of weekends: 939
  4.  
shamsm
Apprentice
Apprentice
LTD Bronze - Rating: 47
 
Posts: 12
Joined: Wed Jul 30, 2008 10:09 am

Re: LTD Puzzle 10 - Weekends between two dates

Postby AlexCuse on Tue Aug 12, 2008 2:53 am

F# has some really cool functions for things like this

Code is hidden, SHOW
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021
 
Posts: 5408
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US
Unrated

Re: LTD Puzzle 10 - Weekends between two dates

Postby SQLDenis on Tue Aug 12, 2008 3:44 pm

T-SQL version

Code is hidden, SHOW
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
 
Posts: 21750
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

Postby tisodotsk on Tue Aug 12, 2008 9:09 pm

My solution in PHP:
Code is hidden, SHOW

Output (first 14 lines):
  1. From 20080811 to 20080811 are 0 weekends. |11|
  2. From 20080811 to 20080812 are 0 weekends. |11|12|
  3. From 20080811 to 20080813 are 0 weekends. |11|12|13|
  4. From 20080811 to 20080814 are 0 weekends. |11|12|13|14|
  5. From 20080811 to 20080815 are 0 weekends. |11|12|13|14|15|
  6. From 20080811 to 20080816 are 0.5 weekends. |11|12|13|14|15|16|
  7. From 20080811 to 20080817 are 1 weekends. |11|12|13|14|15|16|17|
  8. From 20080811 to 20080818 are 1 weekends. |11|12|13|14|15|16|17|18|
  9. From 20080811 to 20080819 are 1 weekends. |11|12|13|14|15|16|17|18|19|
  10. From 20080811 to 20080820 are 1 weekends. |11|12|13|14|15|16|17|18|19|20|
  11. From 20080811 to 20080821 are 1 weekends. |11|12|13|14|15|16|17|18|19|20|21|
  12. From 20080811 to 20080822 are 1 weekends. |11|12|13|14|15|16|17|18|19|20|21|22|
  13. From 20080811 to 20080823 are 1.5 weekends. |11|12|13|14|15|16|17|18|19|20|21|22|23|
  14. 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
Apprentice
LTD Bronze - Rating: 62LTD Bronze - Rating: 62
 
Posts: 22
Joined: Fri Aug 08, 2008 12:45 pm
Location: Bratislava, Slovakia

Re: LTD Puzzle 10 - Weekends between two dates

Postby Remou on Tue Aug 12, 2008 10:04 pm

VBA. I hope.

Code is hidden, SHOW
Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948
 
Posts: 5294
Joined: Sun Oct 14, 2007 11:26 am

Re: LTD Puzzle 10 - Weekends between two dates

Postby AlexCuse on Wed Aug 13, 2008 4:09 am

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
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021
 
Posts: 5408
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US
Unrated

Re: LTD Puzzle 10 - Weekends between two dates

Postby traingamer on Tue Aug 19, 2008 9:49 pm

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
  1. ?Retwe(#3-2-2008#, #3-15-2008#)
  2.  3

Sunday to Saturday single week similarly returns 2 when the answer should be 1.
  1. ?Retwe(#3-2-2008#, #3-8-2008#)
  2.  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). :blush:
Greg

People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
User avatar
traingamer
Senior Sage
Senior Sage
LTD Bronze - Rating: 233LTD Bronze - Rating: 233LTD Bronze - Rating: 233LTD Bronze - Rating: 233LTD Bronze - Rating: 233
 
Posts: 1487
Joined: Thu Feb 28, 2008 4:13 pm
Location: St. Louis, MO, US
Unrated

Re: LTD Puzzle 10 - Weekends between two dates

Postby Remou on Tue Aug 19, 2008 9:59 pm

I interpreted

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?
Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948
 
Posts: 5294
Joined: Sun Oct 14, 2007 11:26 am
Unrated

Re: LTD Puzzle 10 - Weekends between two dates

Postby traingamer on Wed Aug 20, 2008 7:46 pm

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
User avatar
traingamer
Senior Sage
Senior Sage
LTD Bronze - Rating: 233LTD Bronze - Rating: 233LTD Bronze - Rating: 233LTD Bronze - Rating: 233LTD Bronze - Rating: 233
 
Posts: 1487
Joined: Thu Feb 28, 2008 4:13 pm
Location: St. Louis, MO, US
Unrated

Re: LTD Puzzle 10 - Weekends between two dates

Postby AlexCuse on Wed Aug 20, 2008 8:00 pm

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.
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021
 
Posts: 5408
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US
Unrated

Re: LTD Puzzle 10 - Weekends between two dates

Postby Emtucifor on Thu Aug 21, 2008 5:12 pm

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! :o
God cries a little bit every time someone builds a database.
User avatar
Emtucifor
Guru
Guru
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030
 
Posts: 2835
Joined: Fri May 30, 2008 9:30 pm
Location: Bellingham, WA
Unrated

Re: LTD Puzzle 10 - Weekends between two dates

Postby SQLDenis on Thu Aug 21, 2008 5:33 pm

I interpreted it as 1/2 + 1 + 1/2 = 2
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
 
Posts: 21750
Joined: Wed Oct 10, 2007 6:43 pm
Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Unrated

Re: LTD Puzzle 10 - Weekends between two dates

Postby AlexCuse on Thu Aug 21, 2008 5:43 pm

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
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021
 
Posts: 5408
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US
Unrated

Re: LTD Puzzle 10 - Weekends between two dates

Postby Emtucifor on Thu Aug 21, 2008 6:39 pm

And 1 + 1/2 = 1.5?
God cries a little bit every time someone builds a database.
User avatar
Emtucifor
Guru
Guru
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030
 
Posts: 2835
Joined: Fri May 30, 2008 9:30 pm
Location: Bellingham, WA
Unrated

Re: LTD Puzzle 10 - Weekends between two dates

Postby SQLDenis on Thu Aug 21, 2008 7:33 pm

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
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
 
Posts: 21750
Joined: Wed Oct 10, 2007 6:43 pm
Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Unrated

Re: LTD Puzzle 10 - Weekends between two dates

Postby traingamer on Fri Aug 22, 2008 5:30 pm

Late entry

Code is hidden, SHOW
Greg

People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
User avatar
traingamer
Senior Sage
Senior Sage
LTD Bronze - Rating: 233LTD Bronze - Rating: 233LTD Bronze - Rating: 233LTD Bronze - Rating: 233LTD Bronze - Rating: 233
 
Posts: 1487
Joined: Thu Feb 28, 2008 4:13 pm
Location: St. Louis, MO, US

Re: LTD Puzzle 10 - Weekends between two dates

Postby chrissie1 on Thu Aug 28, 2008 7:23 pm

The winners have been determined!

Peoples Champ: shamsm

LTD Admins Champion - traingamer.

Congratulations!
pink fuzzy slippers
User avatar
chrissie1
Senior Guru
Senior Guru
LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088
LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088
LTD Gold - Rating: 2088LTD Gold - Rating: 2088
 
Posts: 9348
Joined: Wed Oct 10, 2007 7:18 pm
Location: Belgium
Unrated