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
def series(l, r) | |
if r - l <= 1 | |
p = (2 * r - 1) * (6 * r - 5) * (6 * r - 1) | |
q = r * r * r * 10939058860032000 | |
a = (r % 2 == 0 ? 1 : -1) * (13591409 + 545140134 * r) | |
[p, q, a * p] | |
else | |
m = (l + r) / 2 | |
p0, q0, t0 = series(l, m) |
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
# https://gist.github.com/gongo/c404167ae49165acd4df63c27ae1a54c | |
# iseqの中から [:putobject, object], :RUBY_EVENT_RETURN や [:putstring, "string"], ?, :RUBY_EVENT_RETURN を雑に探す作戦 | |
def nanika_no_method(code) | |
flat_iseq = RubyVM::InstructionSequence.new(code).to_a.flatten | |
flat_iseq.select.with_index do |s, idx| | |
flat_iseq[idx + 1, 2].include?(:RUBY_EVENT_RETURN) && %i[putobject putstring].include?(flat_iseq[idx - 1]) | |
end.uniq | |
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
#! ./ruby -I.ext/x86_64-darwin14 --disable-gems | |
require '-test-/iseq_load/iseq_load' | |
def spaghetti(&block) | |
iseq_data_magic_index = 0 | |
iseq_data_major_version_index = 1 | |
iseq_data_minor_version_index = 2 | |
iseq_data_format_type_index = 3 | |
iseq_data_misc_index = 4 | |
iseq_data_label_index = 5 |
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
#coding: utf-8 | |
class Te | |
attr_accessor :te_num | |
def initialize num=nil | |
self.te_num = num ? num % 3 : rand(3) | |
end | |
def > te | |
(te_num + 1) % 3 == te.te_num |