#!/usr/bin/perl -w
use strict;
my %tried = ();
main();
sub main {
my @rules = (
\&rule_one,
\&rule_two,
\&rule_three,
\&rule_four,
);
my $axiom = 'MI';
my @path;
my @tries;
solve($axiom, \@rules);
}
sub solve {
my @app;
my ($axiom, $rules) = @_;
my $i = 0;
foreach(@$rules){
my $tmp = $_->($axiom);
push(@app, $tmp) if $tmp;
}
foreach(@app){
next if $tried{$_};
next unless (length($_) < 1000);
print $_ . "\n";
$tried{$_} = 1;
if($_ eq 'MU'){
print "YES!\n\n\n";
exit;
}
solve($_, $rules);
}
}
sub rule_one {
# If any string ends in I, you can append U
my $str = shift;
if ($str =~ m/I$/){
return $str . 'U';
}else{
return undef;
}
}
sub rule_two {
# If any string begins with M,
# you can duplicate the string after M,
my $str = shift;
if($str =~ /^M/){
return 'M' . substr($str, 1) . substr($str, 1);
}else{
return undef;
}
}
sub rule_three {
# If any string contains III,
# you can replace the III with U
my $str = shift;
if($str =~ /III/){
$str =~ s/III/U/g;
return $str;
}else{
return undef;
}
}
sub rule_four {
#If any string contains UU,
# you can delete the UU
my $str = shift;
if($str =~ /UU/){
$str =~ s/UU//g;
return $str;
}else{
return undef;
}
}I thoroughly enjoyed it, but I've always had diverse interests and the book sort of caters to that.
If you approach it as an object of art, the book is fun because it embeds into itself many of the techniques and principles it describes (but you'll only notice this if you're paying attention). This is kinda cool on a meta-meta level because the central concept of the book is self-referentiality.
The GEB book doesn't have all the details, but it uses the ASCII representations (actually base 20 but whatever). With the ASCII representation the theorem feels obvious.
It is a lot of fluff and meandering, but the dialogue are just too good, and I still enjoy them.
Some people have recommended reading "I am a strange loop" as a basically more mature and better written version of GEB.