Next Friday the 13th What is the shortest program that can predict the next time Friday will fall on the 13th day of the month?


Must be an complete functioning program (not just a function/subroutine)
Must print out date in the following format: YYYY-MM-DD
Allow user to provide a start date either as a command line argument or through STDIN
If user provides no start date, use today as the start date.
If the start date is a Friday the 13th, the program should find the next Friday the 13th.


If I were to run the program today (Feb 16 2011) I should get the following output.

$ ./fr13th 2013-05-09
2013-09-13
$ ./fr13th 2007-06-29
2007-07-13
$ ./fr13th 2007-07-13
2008-06-13
$ ./fr13th
2011-05-13
Windows PowerShell, 74
for($d=&quot;date $args&quot;|iex;($d+='1').day*$d.dayofweek-65){}'{0:yyy-MM-d}'-f$d

Fairly straightforward. One perhaps confusing bit is the use of &quot;Get-Date $args&quot; | Invoke-Expression to get either the current date (if $args is empty) or the date specified in $args without raising an error.
72-byte variant:
for($d=&quot;date $args&quot;|iex;($d+=9).day*$d.dayofweek-65){}'{0:yyy-MM-d}'-f$d

Takes ages, though ... this doesn't increment the datetime by a whole day each iteration but instead only 900 nanoseconds. But two bytes shorter.
67-byte variant:
for($d=&quot;date $args&quot;|iex;($d+='1').day*$d.dayofweek-65){}'{0:d}'-f$d

This is a bit locale-sensitive; if it fails on your machine, try setting your date format to ISO-8601 beforehand. :-)
Oh, and it can be made into 65 bytes just like the 72-byte version.
History:

2011-02-17 00:33 (92) First attempt.
2011-02-17 00:35 (85) Improved getting an initial date.
2011-02-17 00:37 (79) Compared the product instead of day and day of week individually. Admittedly stolen from Ventero.
2011-02-17 00:40 (76) Pulled the first line into the for. Comparison just as subtraction instead of -eq which saves another two bytes.
2011-02-17 00:53 (75) Unix date format string is a bit shorter.
2011-02-17 11:42 (74) Reverted to the default date pattern but yyy-MM-d suffices (since the year is always longer than three characters and the day is always 13. Thanks to Ty Auvil for this.