日本でもWiredが取り上げて知られるようになった2,3 Turing Machineですが、
- Wolfram Blog: The Prize Is Won; The Simplest Universal Turing Machine Is Proved
- WIRED VISION / 「ウルフラム氏のチューリングマシン」を20歳の学生が証明
この証明に、Perlが使われていますというお話。
http://www.wolframscience.com/prizes/tm23/TM23Proof.pdf - 証明のPDF
I have written several Perl programs, to demonstrate the constructions given in the proof and to interpret the systems given in various conjectures.
例えばこんな感じ。
cytag.pl#!/bin/perl -w use strict; my $working; my @rules; my $rulecount=0; my $temp; my $temp2; my $doubling=0; # If a Y is given as the first argument, double each element of the output to # show the similarity to system 5 $ARGV[0]eq'Y' and do{$doubling=1; shift @ARGV;}; # Read from file $ARGV[0]eq'F' and do{ shift @ARGV; my $file = shift @ARGV; local $/ = undef; open INFILE, $file; @ARGV = split(' ',<INFILE>); close INFILE; }; $|=1; # Load the working string $working=shift @ARGV; chomp $working; # Load the rules for my $e (@ARGV) { chomp $e; $e eq '""' and $e = ''; $rules[$rulecount++]=$e; } while($working ne '') { # Remove and print the first element of the working string $temp=substr $working,0,1,''; print $temp; $doubling and print $temp; push @rules, ($temp2 = shift @rules); $temp eq '1' and $working .= $temp2; } print "\n";
見てのとおり、ベストプラクティス的とはいえないまでも(例えば whatever if wheneverでなくwhenever and whateverという書き方)、なかなかきれいかつ現代的。Perlをプログラミング言語というより高級シェルとして使う人の多くはもっと「はっちゃけた」書き方をするのですが、意外なところで驚かせてもらいました。
こういう使い方は私もよくやります。この手の問題では、紙に数式書くより楽ですね。
バズル解きにもperlというお話でした。
Dan the (Math|Perl) Monger
追記:Appendixの方にmathematicaのコードがあります。
このブログにコメントするにはログインが必要です。
さんログアウト
この記事には許可ユーザしかコメントができません。