Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict "vars";
- use warnings;
- system('clear');
- our @tape;
- our $pos = 15;
- our @sa= qw(1>b 1>~);
- our @sb= qw(0>c 9>b);
- our @sc= qw(1<c 9<a);
- our %instruction = (
- '1' => sub { $tape[$pos] = '1' },
- '0' => sub { $tape[$pos] = '0' },
- '9' => sub { $tape[$pos] = &randbit },
- '<' => sub { --$pos },
- '>' => sub { ++$pos },
- '~' => sub { print "END OF CALCULATION\n" ; exit 0 },
- );
- for ('a' .. 'z') { $instruction{$_} = sub { init("s".$_) } }
- { push @tape,'0' ; redo unless scalar @tape == 31 }
- sub exec {
- for ( unpack("(A1)*", $_[0]) ) {
- &{$instruction{$_}};
- select(undef, undef, undef, 0.025);
- print &print_tape . "\n";
- } # the game.
- }
- sub init { ($_) = @_; ($tape[$pos] == 0) ? {&exec(${$_}[0])} : { &exec(${$_}[1]) } }
- sub print_tape {
- my $t = join '', @tape;
- $t =~ s/(^.{$pos})(.)(.*$)/\033[0m${1}\033[1;37m${2}\033[0m${3}/;
- print $t;
- return "";
- }
- sub randbit {
- open(RAND,"/dev/urandom") or die;
- ord getc RAND > 127 ? 1 : 0;
- close(RAND)
- }
- init('sa');
Add Comment
Please, Sign In to add comment