2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

13日の金曜日を返すプログラム

Last updated at Posted at 2015-03-07

#13日の金曜日を返すプログラム
今年2015年は「13日の金曜日」が3回もありジェイソンさんが
忙しいというのをどこかでみたので、ツェラーの公式を使って作ってみました。
##ソースコード

jason.rb
# coding: utf-8

def yearSplit(year)
	array = []
	str = year.to_s
	array.push(str.slice!(0,2).to_i)
	array.push(str.to_i)
	return array
end

def getDayOfWeek(year, month, day)
	case month
	when 3..12
		y = yearSplit(year)
		m = month
	else
		y = yearSplit(year-1)
		m = month+12
	end
	d = day
	h = ( y[1] + (y[1]/4).floor + (y[0]/4).floor - 2*y[0] + (13*(m+1)/5).floor + d ) % 7
	return h==0 ? 7 : h
end

puts "Please input the year."
year = gets.to_i
for month in 1..12
	if getDayOfWeek(year, month, 13) == 6
		print "#{month}/13\t"
	end
end
puts

##実行結果

$ ruby jason.rb
Please input the year.
2015
2/13	3/13	11/13
2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?