Login or Sign Up to become a member!
LessThanDot Sit 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 friendfeed 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.

Forum Statistics

Users
Members:
543
Members Online:
6
Guests Online:
6

Total Post History
Posts:
45703
Topics:
9396

7-Day Post History
New Posts:
342
New Topics:
80
Active Topics:
88

Our newest member
sangeeta

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!
And we have contraptions like computers that cheat you out of becoming. Bill Gates says, "Wait till you see what your computer can become." But it's you who should be doing the becoming, not the damn fool computer.

My Crummy Web Page
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
 
Posts: 3532
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
And we have contraptions like computers that cheat you out of becoming. Bill Gates says, "Wait till you see what your computer can become." But it's you who should be doing the becoming, not the damn fool computer.

My Crummy Web Page
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
 
Posts: 3532
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: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467
LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467
LTD Gold - Rating: 1467
 
Posts: 11778
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: 59LTD Bronze - Rating: 59
 
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
x
User avatar
Remou
LTD Admin
LTD Admin
LTD Silver - Rating: 427LTD Silver - Rating: 427LTD Silver - Rating: 427LTD Silver - Rating: 427LTD Silver - Rating: 427
LTD Silver - Rating: 427LTD Silver - Rating: 427
 
Posts: 3160
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 ;)
And we have contraptions like computers that cheat you out of becoming. Bill Gates says, "Wait till you see what your computer can become." But it's you who should be doing the becoming, not the damn fool computer.

My Crummy Web Page
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
 
Posts: 3532
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
Sage
Sage
LTD Bronze - Rating: 148LTD Bronze - Rating: 148LTD Bronze - Rating: 148
 
Posts: 989
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?
x
User avatar
Remou
LTD Admin
LTD Admin
LTD Silver - Rating: 427LTD Silver - Rating: 427LTD Silver - Rating: 427LTD Silver - Rating: 427LTD Silver - Rating: 427
LTD Silver - Rating: 427LTD Silver - Rating: 427
 
Posts: 3160
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
Sage
Sage
LTD Bronze - Rating: 148LTD Bronze - Rating: 148LTD Bronze - Rating: 148
 
Posts: 989
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.
And we have contraptions like computers that cheat you out of becoming. Bill Gates says, "Wait till you see what your computer can become." But it's you who should be doing the becoming, not the damn fool computer.

My Crummy Web Page
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
 
Posts: 3532
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
It's more cheesier if you do it right the first time!
User avatar
Emtucifor
Senior Sage
Senior Sage
LTD Gold - Rating: 753LTD Gold - Rating: 753LTD Gold - Rating: 753LTD Gold - Rating: 753LTD Gold - Rating: 753
LTD Gold - Rating: 753LTD Gold - Rating: 753LTD Gold - Rating: 753LTD Gold - Rating: 753LTD Gold - Rating: 753
LTD Gold - Rating: 753
 
Posts: 2152
Joined: Fri May 30, 2008 9:30 pm
Location: California
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: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467
LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467
LTD Gold - Rating: 1467
 
Posts: 11778
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.
And we have contraptions like computers that cheat you out of becoming. Bill Gates says, "Wait till you see what your computer can become." But it's you who should be doing the becoming, not the damn fool computer.

My Crummy Web Page
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642LTD Silver - Rating: 642
 
Posts: 3532
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?
It's more cheesier if you do it right the first time!
User avatar
Emtucifor
Senior Sage
Senior Sage
LTD Gold - Rating: 753LTD Gold - Rating: 753LTD Gold - Rating: 753LTD Gold - Rating: 753LTD Gold - Rating: 753
LTD Gold - Rating: 753LTD Gold - Rating: 753LTD Gold - Rating: 753LTD Gold - Rating: 753LTD Gold - Rating: 753
LTD Gold - Rating: 753
 
Posts: 2152
Joined: Fri May 30, 2008 9:30 pm
Location: California
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: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467
LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467LTD Gold - Rating: 1467
LTD Gold - Rating: 1467
 
Posts: 11778
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
Sage
Sage
LTD Bronze - Rating: 148LTD Bronze - Rating: 148LTD Bronze - Rating: 148
 
Posts: 989
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!
User avatar
chrissie1
LTD Admin
LTD Admin
LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264
LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264LTD Gold - Rating: 1264
LTD Gold - Rating: 1264
 
Posts: 6038
Joined: Wed Oct 10, 2007 7:18 pm
Location: Belgium
Unrated