#!/usr/bin/perl -w # (c) Declan Malone 2008 # Licensed under the terms of GPL 2 or later at your discretion # Spurious info at project343.blogspot.com sub quine { # agent for traversing a bi-coloured hexagonal space my $colouring_mod3=shift; # ref to list of colours [0,1,2] my $colouring_mod7=shift; # ref to list of colours [0,1,2,3,4,5,6] my $construction=shift; # debug trail my ($t0,$t1,$t2)=@$colouring_mod3; my ($s0,$s1,$s2,$s3,$s4,$s5,$s6)=@$colouring_mod7; my $methods= { "STEP" => # forward one step (0->1) sub { push @$construction, "STEP3 $t0 $t1"; push @$construction, "STEP7 $s0 $s1"; quine([$t1,$t2,$t0],[$s1,$s3,$s5,$s2,$s0,$s6,$s4],$construction); }, "LEFT" => # turn left 60 degrees sub { push @$construction, "LEFT"; quine([$t0,$t2,$t1],[$s0,$s6,$s1,$s2,$s3,$s4,$s5],$construction); }, "RIGHT" => # turn right 60 degrees sub { push @$construction, "RIGHT"; quine([$t0,$t2,$t1],[$s0,$s2,$s3,$s4,$s5,$s6,$s1],$construction); }, "SELF" => sub { push @$construction, "SELF"; return ($t0,$s0); }, "SELVES" => sub { push @$construction, "SELVES"; return ($colouring_mod3,$colouring_mod7); }, "TRAIL" => sub { $construction; } }; return $methods; } my ($threes,$sevens); my $trail=[]; $h=quine([0..2],[0..6],$trail); print "I start at 0 in both three-coloured and seven-coloured space.\n"; print "The environment in the respective spaces are [0,1,2] and [0,1,2,3,4,5,6].\n"; $h=$h->{STEP}->(); $h=$h->{LEFT}->(); $h=$h->{STEP}->(); $h=$h->{RIGHT}->(); $h=$h->{STEP}->(); ($three,$seven)=$h->{SELF}->(); ($threes,$sevens)=$h->{SELVES}->(); #print "threes is $threes and its ref is ", ref($threes), "\n"; #print "sevens is $sevens and its ref is ", ref($sevens), "\n"; print "I am now at $threes->[0] in 3-space and $sevens->[0] in 7-space.\n"; print "I am now at $three in 3-space and $seven in 7-space.\n"; print "(the above two lines should print the same)\n"; print "The environment in 3-space is (", (join ",", @$threes), ")\n"; print "The environment in 7-space is (", (join ",", @$sevens), ")\n"; print "My tape reads:\n ", (join "\n ", @{$h->{TRAIL}->()}), "\n";