This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ref: | |
# http://blog.kymmt.com/entry/hook-by-alias-chaining-in-ruby | |
# http://miyohide.hatenablog.com/entry/2014/02/28/203743 | |
module AddLogging | |
def self.included(base) | |
base.extend HookMethod | |
end | |
module HookMethod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
def measure_do | |
result = Benchmark.measure do | |
yield | |
end | |
puts Benchmark::CAPTION | |
puts result | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
def step_count(a, b, n) | |
if a + b >= n | |
@count += 1 if a + b == n | |
return | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
def search_reversible_num(offset) | |
i = offset; | |
loop do | |
n2 = i.to_s(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
def print_enable_combinarion(from, to) | |
(from..to).each do |num| | |
nums = num.to_s.split('') | |
puts num if enable_combinarion?(nums) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
def reverse_card_open(card_num) | |
cards = Array.new(card_num, false) | |
1.upto(card_num) do |i| | |
i.step(card_num, i+1) do |j| | |
cards[j] = !cards[j] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
def cut_bar(bar, m) | |
t = m | |
rt_bar = bar.dup | |
bar.each_with_index do |b, i| | |
if b > 1 | |
t -= 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module M1 | |
end | |
module M2 | |
include M1 | |
end | |
module M3 | |
prepend M1 | |
include M2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
def pair2one(num) | |
@count = 0 | |
countup(0, num) # 男子が先頭の場合を計上. | |
countup(1, num) # 女子が先頭の場合を計上. | |
puts @count | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
ROOT_NUM = [4, 9, 16, 25, 36, 49, 64] | |
def ichigo | |
@result = [] | |
(2..(ROOT_NUM[-1] / 2)).each { |i| search_pair(1, (2..i).to_a, [1]) } | |
p @result |
OlderNewer