トップ «前の日記(2018年01月06日) 最新 次の日記(2018年01月13日)» 編集

GREEN HARMONY 手記

アニメ、ドラマ、音楽、読書、プログラミングのメモ等

朝ドラは「おかえりモネ」から視聴開始。過去作も少しずつ見始めています。

好きなアニメ: 響け!ユーフォニアムちはやふる

音楽:吉田拓郎、浅川マキ 他

外国語学習:基本文法から学ぶ 英語リーディング教本 (薬袋善郎 著),フランス語のしくみ(佐藤康 著) カラー改訂版 まるおぼえ英単語2600(小倉弘 著),基礎がため 一生モノの英文法 BASIC(澤井康佑 著)世界一簡単なフランス語の本 すぐに読める、読めれば話せる、話せば解る! (中条省平 著)

本ページはプロモーションが含まれています

訪問者数

合計: 今日: 昨日:

プライバシーポリシー
検索キーワード:

2018年01月08日 40日暦(ruby) [長年日記]

40日暦

cal40.rb

require 'date'


def cal40 date
  ary = []
  (1 .. 9).each {|mm|
    max = 
    if mm.odd?
      41
    else
      if mm == 2 and date.leap?
        41
      else
        40
      end
    end
    
    (1 .. max).each {|dd|
      ary << [mm,dd]
    }
  }
  ary
end

light_next.rb

def next1 ary
  
  h = {2=>4,
    4=>6,
    6=>2,
    3=>5,
    5=>7,
    7=>3,
    1=>8,
    8=>9,
    9=>1
  }
  n3 = h[ary[ary.length-1]];
  [ary[0],to9(9+(n3-ary[0])),n3]

end

def to9 n
  result = n % 9
  if result == 0 then 9; else  result end

end

4.rb (6人の計算の表示)

require './cal40'
require './light_next'

ary = nil

aDate =
	(if ARGV[0]
		Date.parse(ARGV[0])
	else 
		Date.today
	end)

ary1 = []
ary2 = []

n1 = to9(aDate.year)
n2 = to9(aDate.month+aDate.day)
n3 = to9(n1 + n2)
ary1 << [n1,n2,n3]
ary1 << next1(ary1.last)
ary1 << next1(ary1.last)

aCal40 = cal40 aDate

lightmd = aCal40[aDate.yday-1]
n22 = to9(lightmd[0] + lightmd[1])
n23 = to9(n1 + n22)

ary2 << [n1,n22,n23]
ary2 << next1(ary2.last)
ary2 << next1(ary2.last)

print aDate,"\n"

ary3 = ary1.zip(ary2).flatten(1)
ary3.each_with_index {|elm,i|
  case i
  when	0
		print "◎"
  when  1
  		print "○"
  else
      	print " "  
  end
  print elm.join,"\n"
}


実行

% ruby 4.rb

2018-01-08
◎292
○292
 224
 224
 246
 246


プロを目指す人のためのRuby入門 言語仕様からテスト駆動開発・デバッグ技法まで Software Design plus