Skip to main content
added 159 characters in body
Source Link
sepp2k
  • 1.9k
  • 1
  • 18
  • 16

Ruby, 9396 75 characters

require"date"
$><<(Dated=Date.parse($*[0]||Date.today.to_sgets||"thu")+1..1.0/0).find{|d|d
d+=1 while d.wday==5&&dwday*d.day==13}day!=65
$><<d

Takes the date from stdin. To not specify a date press ctrl-d.

Thanks very much for Ventero's help.

Ungolfed:

require "date"
$stdout <<# (Date.parse(ARGV[0]||Date.today.to_s)+1..Float::INFINITY"thu") will return this week's thursday
date = Date.findparse(gets do|| |d|"thu")+1
date += 1 while d.wday == 5 &&* d.day ==!= 5 * 13
end$stdout << date

Sample IO:

$ ruby fr13th.rb  
2013-05-09
2013-09-13
$ ruby fr13th.rb  
2007-06-29
2007-07-13
$ ruby fr13th.rb  
2007-07-13
2008-06-13
$ ruby fr13th.rb
2011-05-13

Ruby, 93 characters

require"date"
$><<(Date.parse($*[0]||Date.today.to_s)+1..1.0/0).find{|d|d.wday==5&&d.day==13}

Ungolfed:

require "date"
$stdout << (Date.parse(ARGV[0]||Date.today.to_s)+1..Float::INFINITY).find do |d|
  d.wday == 5 && d.day == 13
end

Sample IO:

$ ruby fr13th.rb 2013-05-09
2013-09-13
$ ruby fr13th.rb 2007-06-29
2007-07-13
$ ruby fr13th.rb 2007-07-13
2008-06-13
$ ruby fr13th.rb
2011-05-13

Ruby, 96 75 characters

require"date"
d=Date.parse(gets||"thu")+1
d+=1 while d.wday*d.day!=65
$><<d

Takes the date from stdin. To not specify a date press ctrl-d.

Thanks very much for Ventero's help.

Ungolfed:

require "date"
# Date.parse("thu") will return this week's thursday
date = Date.parse(gets || "thu")+1
date += 1 while d.wday * d.day != 5 * 13
$stdout << date

Sample IO:

$ ruby fr13th.rb 
2013-05-09
2013-09-13
$ ruby fr13th.rb 
2007-06-29
2007-07-13
$ ruby fr13th.rb 
2007-07-13
2008-06-13
$ ruby fr13th.rb
2011-05-13
Source Link
sepp2k
  • 1.9k
  • 1
  • 18
  • 16

Ruby, 93 characters

require"date"
$><<(Date.parse($*[0]||Date.today.to_s)+1..1.0/0).find{|d|d.wday==5&&d.day==13}

Ungolfed:

require "date"
$stdout << (Date.parse(ARGV[0]||Date.today.to_s)+1..Float::INFINITY).find do |d|
  d.wday == 5 && d.day == 13
end

Sample IO:

$ ruby fr13th.rb 2013-05-09
2013-09-13
$ ruby fr13th.rb 2007-06-29
2007-07-13
$ ruby fr13th.rb 2007-07-13
2008-06-13
$ ruby fr13th.rb
2011-05-13