月齢を計算してみる
30分プログラム、その654。http://gauc.no-ip.org/awk-users-jp/blis.cgi/DoukakuAWK_214をマネしました。
単純にマネするだけではおもしろくないので、月名を出すようにしてみました。
でも、まあ、今日の月齢を出すだけなので、空を見上げたほうが早いと思うよ。
使い方
$ perl moon.pl 15 満月/望月
ソースコード
#! /usr/bin/perl # -*- mode:perl; coding:utf-8 -*- # # moon.pl - # # Copyright(C) 2009 by mzp # Author: MIZUNO Hiroki / mzpppp at gmail dot com # http://howdyworld.org # # Timestamp: 2009/09/05 22:07:35 # # This program is free software; you can redistribute it and/or # modify it under MIT Lincence. # use strict; use warnings; use Data::Dumper; sub moon($$$){ my ($day,$mon,$year) = @_; my %const = ( 0=>0, 1=>2, 2=>0, 3=>2, 4=>2, 5=>4, 6=>5, 7=>6, 8=>7, 9=>8, 10=>9, 12=>10); (($year-11)%19*11+$const{$mon}+$day)%30; } my %names = ( 1 => '新月', 2=> '既朔', 3 => '三日月', 7 => '上弦', 8 => '上弦', 13 => '十三夜', 14 => '小望月/幾望', 15 => '満月/望月', 16=>'十六夜/既望', 17=>'立待月', 18=>'居待月', 19 =>'寝待月/臥待月', 20=>'更待月', 22=>'下弦', 23=>'下弦', 29=>'晦', 30=>'晦'); my ($sec,$min,$hour,$day,$mon,$year) = localtime(); my $moon = moon($day,$mon,$year); print "$moon $names{$moon} \n";