Saturday, January 24, 2009

Project Euler and PowerShell - Problem 19

Eleven down, 14 more to go before I reach level 1 (tetrahedron) on Project Euler. This one was easy if you know what PowerShell can do with dates!

How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?

$startDate = Get-Date "01/01/1901"
$endDate = Get-Date "12/31/2000"
$cnt = 0
for($date=$startDate; $date -lt $endDate; $date = $date.AddMonths(1))
if ($date.DayOfWeek -eq 'Sunday')

1 comment:

Anonymous said...

Thank you so much for this post, it was very insightful!
Reverse Phone Lookup also contains hundreds of cell phone and telecommunications articles and resources covering all aspects of cell phone safety, security, accessories and shopping.
Phone Number Trace Reverse Phone Lookup, Unknown Number Search - welcome to visit More Reviews.