(Following the 1st part )

Write Your Own Machine

File machines/an_irrational_number.machine includes all the fundamental elements to create your own Turing Machine.

  • The lines start with semicolons are comments.
  • Non-comment non-empty lines are m-configurations, each of them consists of 4 columns (separated by vertical lines), which in turn are:
    • Name of current m-configuration.
    • The symbol read from current square of the tape—m-configurations with same name could behave differently while reading different symbols.
    • Operations, separated by commas. Valid operations are:
      • P{x}: Write {x} to current square of the tape.
      • E: Erase any symbol in current square.
      • L/R: move the cursor one square left/right.
    • Next m-configuration—what should be done after current m-configuration?

Now, try to write your own machine, and run it!

What’s Next?

Universal Turing Machine , of course. (What else otherwise?)

(It requires reading Chapter 7 and 9 of The Annotated Turing . Although I haven’t started yet, I can feel it’s not an easy task. Any contribution would be highly appreciated.)

Meanwhile, I started building a web UI running Turing Machines with Compojure . Take a look at web folder. You can trial it with:

$ lein ring server

It also makes sense to tidy it up and make it more interactive.

I also want to build an iOS application…but that’s another story.

You might want to try something more interesting, e.g. to write a general Turing Machine to determine any given Turing Machine would halt or not; to solve the Entscheidungsproblem ; etc.

Anyway, enjoy :D

Spent about 10 hours, I wrote my first program with Clojure : an implementation of Turing Machine as described in Alan Turing’s famous paper ” On Computable Numbers, With An Application To The Entscheidungsproblem ”.

(Note: Charles Petzold’s book The Annotated Turing is a good point to understand Turing’s paper.)

Get Started

First of all, you need clone the codebase from GitHub:

$ git clone git://github.com/gigix/turing_machine.git

In order to build it, you also need install Leiningen—which is pretty easy on my MacBook Pro with MacPorts:

$ sudo port install leiningen

Now you can build the codebase and see if everything works:

$ cd turing_machine/clojure && ./build.sh

You should see turing_machine-1.0.0-SNAPSHOT-standalone.jar being packaged, as well as a “tape” being printed as following:

(0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1)

That’s the binary form of rational number 1/3 (0.010101…). You just executed a Turing Machine which calculates 1/3 and prints the result to a tape—actually we only calculate and display the starting 10 squares of the tape, because it’s simply impossible to finish the calculation, because it’s infinite.

Calculate An Irrational Number

There’s another machine lays in machines/an_irrational_number.machine, which calculates an irrational number with following form:

0.01011011101111011111…

You can run this machine with following instruction—the algorithm is more complicated, so you have to run more steps to see a reasonable shape:

$ java -jar turing_machine-1.0.0-SNAPSHOT-standalone.jar machines/an_irrational_number.machine 1000

The starting part of the tape looks like following:

And here’s the “source code” (formal name should be “m-configurations”, in which “m” stands for “machine”) of this machine, which I will explain in more detail in next section:

(To be continued…)

晒晒我的开源项目们

October 6th, 2011

在等“bundle install”的时候闲着没事,打开 我的Github ,发现还有那么一些东西值得分享一下的。

啤酒游戏 :《 第五项修炼 》里讲的啤酒游戏。多人协作游戏,适合培训时候用。培训详情请联系 小刀

合作的进化 :这就是《 合作的进化 》那本书里讲的生存竞赛游戏。可以自己写新的策略放进来,看看重复囚徒困境中的最佳策略是如何被选择出来的。

Jungling :作为技术人员的TWer到客户现场启动一个新项目时需要注意哪些事?带上iPad和Jungling,你的丛林冒险手册就有了。

每天一小时1.HourFor.Me 的源代码。每天一小时,每月就能做成一件事。欢迎贡献,如果从代码里发现了漏洞,还望高抬贵手请勿攻击。

TRSSTRSS 的源代码。 把RSS同步到新浪微博(因为新浪自己的同步功能貌似不工作了)。后面还可以有很多发展,例如同步到各种微博之类的。同样,欢迎贡献代码,多谢请勿攻击。

jquery.image-preview :一个比较体面的图片预览插件,实现就像Google Images那样的 效果 :鼠标悬停在小图片上,小图片就会放大预览。主要的难点是当小图片位于页面边缘时,预览也要出现在合适的位置。

图灵机 :这两天开始写的,照着 图灵的论文 ,用 Clojure 实现一个原模原样的图灵机。后面也许还想在iOS上实现一个有图形界面的。

发现我的开源项目们有个共通的问题:虎头蛇尾。每个点子都没有耐性深挖下去。想写代码练手的年轻同事们可以找我啊,我这里要干的活很多的⋯⋯