Skip to content

Instantly share code, notes, and snippets.

<!-- 白黒画像を透過画像に変換する -->
<body bgcolor="blue">
<script>
let img=new Image;
img.src="hierarchy-000001.png";
img.onload=()=>{
let canvas=document.createElement("canvas");
canvas.width=img.width;
canvas.height=img.height;
let ctx=canvas.getContext("2d");
class Complex {
x: number;
y: number;
constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
add(other: Complex) {
# sqrt(-1) in Q_5
require "mathn"
def e_p_int(x, p)
e = 0
while x % (p**e) == 0
e += 1
end
e - 1
Dir.glob("*.html").each do |fname|
str = File.read(fname)
if str !~ /<meta charset=/
str = str.sub(/<head\b[^>]*>/) {|s| s + '<meta charset="utf-8">' }
File.write(fname, str)
end
end
@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
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
class Tape
def initialize
@array = [0]
@head = 0
end
attr_accessor :array, :head
def read
@array[@head]
# 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
/* 関数プログラムのインタプリタ */
/* すなわち,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);
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|