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
; 数列G(p)の第q項がnであるとき、そのqの値を返す | |
(define (g p n) | |
(let ((first (/ (* (+ p 1) p) 2) ) | |
(tolerance p)) | |
(if (= 0 (modulo (- n first) tolerance)) | |
(+ (/ (- n first) tolerance) 1) | |
0))) | |
; ステップ・アップ・サムを求める | |
(define (step-up-sum n) |
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
# 数列G(p)を示すクラス | |
class G | |
def initialize(p) | |
@p = @torelance = p # 公差 | |
@first = (1 + p) * p / 2 # 初項 | |
end | |
attr_reader :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
# 数学的な処理をまとめた名前空間 | |
class MathEx | |
# 1からnの階乗を行う | |
def self.fact(n) | |
(1..n).inject(:*) | |
end | |
# nPrを計算する | |
def self.p(n, 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
# == 基本方針 == | |
# t = i ** 2 + j ** 2 を考える | |
# t の下 m けたは i ** 2 と j ** 2 の下 m けたに依存する | |
# また i ** 2 と j ** 2 の下 m けたは、それぞれ i と j の下 m けたに依存する | |
# つまり i と j を 1の位 => 10の位 => 100の位 => ... と確定させていけば | |
# t も 1の位 => 10の位 => 100の位 => ... の順に確定していく | |
# == 具体的な方針 == | |
# ...0...5 のような数字が存在するとする | |
# このとき ...0 ** 2 + ...5 ** 2 = ...5 より、条件をみたす |
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
#include <iostream> | |
#include <vector> | |
using namespace std; | |
// プロトタイプ宣言 | |
void vectorPrint(vector<int> v); | |
void inject(vector<int> &v, int l, int r, vector<int> &ans); | |
void merge(vector<int> &v1, vector<int> &v2, vector<int> &ans); | |
void slice(vector<int> &v, int pivot, vector<int> &v1, vector<int> &v2); |
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
class Array | |
def merge(ary) | |
# どちらかの配列が空になるまで、条件にしたがって配列の先頭をtempにpushしていく。 | |
a1, a2, temp = self.dup, ary.dup, [] | |
temp << (a1[0] < a2[0] ? a1.shift : a2.shift) until a1.empty? || a2.empty? | |
temp + a1 + a2 # 残ったものはすべてtmepにpush | |
end | |
def merge_sort |
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
#include <stdio.h> | |
#include <math.h> | |
#define PNUM 10 // 素数の数を定数宣言 | |
// プロトタイプ宣言 | |
void toBinary(int n, int *bin, int binLen); | |
long sum(long n, int left, int right); | |
int count(int n, int *arr, int left, int right); |
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
# 包含と排除の原理によると | |
# a or b or c or d | |
# = (a + b + c + d) segment1 | |
# - (a^b + a^c + a^d + b^c + b^d + c^d) segment2 | |
# + (a^b^c + a^b^d + a^c^d + b^c^d) segment3 | |
# - (a^b^c^d) segment4 | |
# つまりそれぞれの積集合の要素を作る集合の数が奇数のときは足し算、偶数のときは引き算となる。 | |
# 1. 配列primesについて、m個の要素からなる組み合わせを作る。 | |
# 2. それぞれの組み合わせについて、要素を掛け合わせる。例えば[3,5,7]なら105を返す。 |
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
# 9パズルを扱うクラス。 | |
class Pazle | |
# 完成時のパズル。 | |
@@goal_pazle = (1..9).each_slice(3).map(&:to_a) | |
# 2重配列の座標。 | |
@@coordinates = [0,1,2].product([0,1,2]).to_a | |
# パズル完成時、パネルの座標をしめす。 |
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
class Yolang | |
# 引数には解釈したい文字列を指定する | |
def initialize(code) | |
# 引数のstringから必要な文字以外を削除したもの | |
@code = code.gsub(/[^yo!?]?/i,"") | |
@result = [] # 出力結果を順に格納する | |
@memory = [] # 疑似メモリ | |
@memory_ptr = 0 # 疑似ポインタ | |
@funcs = [] # 命令を格納する |