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> | |
| /* 鹿島亮『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 */ |
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
| BITS 32 | |
| segment .text | |
| global _factorial | |
| _factorial: | |
| push ebp | |
| mov ebp, esp | |
| push ebx | |
| mov ebx, [ebp+8] |
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
| # スキャンしたファイルを一括リサイズ&色補正 | |
| # カレントディレクトリにあるすべての.jpg(ただし名前に記号+がつかない)を編集し、 | |
| # 拡張子の前に+をつけて保存します | |
| width = 824 | |
| gamma = 0.4 | |
| Dir.glob("*.jpg").each do |fname| | |
| next if fname =~ /\+\.jpg$/ |
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
| 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; |
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 "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| |
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
| /* 関数プログラムのインタプリタ */ | |
| /* すなわち,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); |
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
| # 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 |
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 Tape | |
| def initialize | |
| @array = [0] | |
| @head = 0 | |
| end | |
| attr_accessor :array, :head | |
| def read | |
| @array[@head] |
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 = <<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 |
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
| /* 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 |