This file contains hidden or 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 'rational' | |
class AugmentedMatrix | |
def initialize a, b, mod | |
@matrix = [] | |
@i_size = a.size | |
@j_size = a[0].size |
This file contains hidden or 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 'rational' | |
class AugmentedMatrix | |
def initialize a, b | |
@matrix = [] | |
@i_size = a.size | |
@j_size = a[0].size |
This file contains hidden or 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 'prime' | |
require 'set' | |
# Euler のファイ関数を計算する | |
def euler_phi m | |
phi = m | |
if Prime.prime? m | |
phi = m-1 |
This file contains hidden or 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
# turing2.tm | |
# 「チューリングを読む」 p.134 参照 | |
# | |
# 入力: なし | |
# 出力: 001011011101111011111... | |
# | |
# チューリングの規約により, | |
# 非周期でかつ1つ飛ばしで打ち込む | |
# | |
# 形式: |
This file contains hidden or 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 'test/unit' | |
# 要 | |
# $ gem install test-unit | |
require 'set' | |
LEFT = 'L' | |
RIGHT = 'R' |
This file contains hidden or 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
# tt21akRW1 さんによる [7, 120] における素数の個数を返す計算式の検証のためのプログラム | |
# 参考URL: http://blogs.yahoo.co.jp/donald_stinger/14413096.html | |
require 'prime' | |
def mod(n, modulo) | |
n.modulo(modulo).to_f | |
end | |
# tt21akRW1 さんによる [7, 120] における素数の個数を返す関数 |
This file contains hidden or 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
########## | |
### 螺旋状に格子点を順に列挙する Enumerator クラス | |
# | |
# -max_levels <= x <= +max_levels | |
# -max_levels <= y <= +max_levels | |
# の範囲の格子点 (x, y) を列挙する | |
# | |
# ただし,中心 (0, 0) から | |
# -> ( 1, 0) -> ( 1, 1) -> ( 0, 1) -> (-1, 1) | |
# -> (-1, 0) -> (-1, -1) -> ( 0, -1) -> ( 1, -1) |
This file contains hidden or 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
# 1変数多項式の展開プログラム | |
class Polynomial | |
@@DEFAULT_MAX_ORDER = 200 | |
@@max_order = @@DEFAULT_MAX_ORDER # 打ち切らずに計算させる最大の次数 ( (MAX_ORDER+1) 以上の次数は打ち切られる ) | |
attr_reader :coefficients, :variable | |
# コンストラクタ |
This file contains hidden or 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
maximum_number = 10000000 | |
# 得られた素数を保管する配列 | |
primes = [] | |
# 素数の候補となる数の配列 | |
numbers = (2..maximum_number).to_a | |
p = numbers.first |
This file contains hidden or 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 'rubygems' | |
require 'gruff' | |
require 'prime' | |
# 配列を宣言 | |
primes = Array.new | |
prev_num = 0 | |
# 素数を生成する上限を決める |