Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
/* 鹿島亮『C言語による計算の理論』の第3章で登場する */
/* 関数left, rightの効率的な実装例 */
/* x^2 <= n を満たす最大のxを求める */
/* バビロニア人の方法 (Babylonian method) を使う */
/* 参考: */
/* http://www001.upp.so-net.ne.jp/y_yutaka/labo/math_algo/math_algo.html */
/* http://cpplover.blogspot.jp/2010/11/blog-post_20.html */
BITS 32
segment .text
global _factorial
_factorial:
push ebp
mov ebp, esp
push ebx
mov ebx, [ebp+8]
# スキャンしたファイルを一括リサイズ&色補正
# カレントディレクトリにあるすべての.jpg(ただし名前に記号+がつかない)を編集し、
# 拡張子の前に+をつけて保存します
width = 824
gamma = 0.4
Dir.glob("*.jpg").each do |fname|
next if fname =~ /\+\.jpg$/
@fujidig
fujidig / Form1.cs
Created April 1, 2016 21:49
c#ランダムウォーク
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
require "set"
# 台集合xにおいてopensetsから生成される位相
def gen_topology(x, opensets)
topo = Set[Set[], x]
topo.merge opensets
q = topo.to_a
while q.size > 0
o = q.shift
topo.to_a.each do |o2|
/* 関数プログラムのインタプリタ */
/* すなわち,compはジャンププログラムのインタプリタだったが */
/* これを第1章で定義される関数プログラムのインタプリタとして */
/* 作ればどの程度複雑になるのか見てみる */
int pair(int x, int y);
int ELM(int a, int i);
int length(int a);
int sequence(int a, int i);
int replace(int a, int i, int x);
# Babylonian method
def isqrt(n)
return 0 if n == 0
s, t = 1, n
while s < t
s *= 2
t /= 2
end
begin
t = s
class Tape
def initialize
@array = [0]
@head = 0
end
attr_accessor :array, :head
def read
@array[@head]
a = <<EOS
0 _ _ R 0
0 1 1 R 1
1 _ 1 R 2
1 1 1 R 1
2 _ _ L 3
2 1 1 R 2
3 _ _ L 3
3 1 _ L 4
@fujidig
fujidig / c-parser.y
Last active September 4, 2016 11:29
/* https://www.lysator.liu.se/c/ANSI-C-grammar-y.html */
%token IDENTIFIER CONSTANT
%token LE_OP GE_OP EQ_OP NE_OP
%token INT
%token IF ELSE WHILE GOTO RETURN
%start translation_unit