2017-01-01から1年間の記事一覧

素因数展開

自然数から始める。 素因数分解して、小さい順に10進表記で並べる。 すると、あら不思議、数列ができる。 ・ ・ ・ 素数になったら終了。はい解散。

Ruby クワイン

言語:Ruby eval a="printf 'eval a=%p',a"

ブッダブロのような何か

言語:mathematica random[] := 4*RandomComplex[] - 2 - 2 I f[z_, c_] := z^2 + c onestep[c_, limit_] := NestWhileList[f[#, c] &, 0, Abs[#] < 2 &, 1, limit] c2pair[z_] := {Re[z], Im[z]} step[limit_, max_] := onestep[#, limit] & /@ Table[random…

オセロ必勝法 Part2

石を返す前に、石を置くのを忘れてました。 あと、initableをちょっと修正しました。 (defun Osero () (let ((table nil)) (defun initable (table sq) (defun initableat (table) (cond ((not table) (setq table '((0 0)))) ((= (cadr (car table)) (1- sq…

オセロ必勝法 Part1

8×8のオセロの必勝法が知りたいので、それを目標にプログラミングしていきたいと思います。 手始めに、オセロ盤のマスを作りました。 言語はEmacs Lispです。 (defun Osero () (let ((table nil)) (defun initable (table sq) (defun initableat (table) (co…

セルオートマトンのルール30の音

言語:mathematica ameba[max_] := Prepend[Table[0, {i, max - 1}], 1] rule30[x_, y_, z_] := If[x == 1, (1 - y) (1 - z), (1 - (1 - y) (1 - z))] evolveat[list_, n_, max_] := (cell = list[[n]]; If[n == 1, leftcell = list[[max]], leftcell = list[…

チューリングマシン

言語:Emacs Lisp (defun turing (input) (let ((tape (make-list 16 0)) (head '(0 0)) (prog nil)) (defun readhead () (elt tape (car head))) (defun writehead (x) (setf (elt tape (car head)) x)) (defun movehead (x) (if (equal x 'R) (setf (car he…

バーニングシップ・フラクタル

言語:Mathematica burnp[c_, limit_, f_] := ( n = 0; z = 0; While[n < limit, z = f[z, c]; If[Abs[z] >= 2, out = False; Break[]] If[n == limit - 1, out = True; Break[]] n++;]; out) list[table_] := ( Map[{Re[#], Im[#]} &, table]) clist[sample_…