LoginSignup
1
1

More than 5 years have passed since last update.

Project Euler Q19 【日曜日の数え上げ】

Last updated at Posted at 2017-11-07

Project Eulerをワンライナーで解いてみる。
間違っていたらコメントください。

問題

次の情報が与えられている.

・1900年1月1日は月曜日である.
・9月, 4月, 6月, 11月は30日まであり, 2月を除く他の月は31日まである.
・2月は28日まであるが, うるう年のときは29日である.
・うるう年は西暦が4で割り切れる年に起こる. しかし, 西暦が400で割り切れず100で割り切れる年はうるう年でない.

20世紀(1901年1月1日から2000年12月31日)中に月の初めが日曜日になるのは何回あるか?

解答

seq 0 $((12*100)) |
awk '{print "date -d \"1901/01/01 "$1" months\" \047+%Y/%m/%d %A\047"}' |
bash |
grep "01 Sun" |
wc -l
171

数学的知識を使用せずdateコマンドでズルをしてしまう方法。
ちなみに\047はシングルクォーテーションのこと。

答え合わせ

こちらのサイト様と一致していればOKとした。
http://kingyojima.net/pje/019.html

1
1
0

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
1
1