View difference between Paste ID: eGARKVVa and gJKizdYS
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/env perl -w
2
3
use common::sense;
4
use autodie;
5
6
my $p = 0;
7
my $lim = 5000;
8
my @a = (1..$lim);
9
my @loop;
10
my $s = 0;
11
12
for my $cnt (1..$lim){
13
	$a[$cnt] = 0;
14
}
15
16
open my $bf, "<", $ARGV[0];
17
my $data;
18
{
19
	local $/;
20
	$data = <$bf>;
21
}
22
23
sub getchar{
24
	chomp (my $in = <>);
25
	return (ord(substr($in,0,1)));
26
}
27
28
foreach my $i (split (//, $data)){
29
	$i = substr($data,$s,1);
30-
   
30+
   		given ( $i ) {
31-
		when ($i eq '+') {$a[$p] = -1 if ($a[$p] == 255); $a[$p]++;}
31+
			when ($i eq '+') {$a[$p] = -1 if ($a[$p] == 255); $a[$p]++;}
32-
		when ($i eq '-') {$a[$p] = 256 if ($a[$p] == 0); $a[$p]--;}
32+
			when ($i eq '-') {$a[$p] = 256 if ($a[$p] == 0); $a[$p]--;}
33-
		when ($i eq '>') {$p = -1 if ($p == $lim); $p++;}
33+
			when ($i eq '>') {$p = -1 if ($p == $lim); $p++;}
34-
		when ($i eq '<') {$p = $lim + 1 if ($p == 0); $p--;}
34+
			when ($i eq '<') {$p = $lim + 1 if ($p == 0); $p--;}
35-
		when ($i eq ','){
35+
			when ($i eq ','){
36-
			$a[$p] = getchar;
36+
				$a[$p] = getchar;
37
			}
38-
		when ($i eq '.'){
38+
			when ($i eq '.'){
39-
			print chr $a[$p];
39+
				print chr $a[$p];
40
			}
41-
		when ($i eq "[") {
41+
			when ($i eq "[") {
42-
			push (@loop, $s);
42+
				push (@loop, $s);
43
			}
44-
		when ($i eq "]") {
44+
			when ($i eq "]") {
45-
			if ($a[$p] != 0) {
45+
				if ($a[$p] != 0) {
46-
				$s = $loop[scalar(@loop) - 1];
46+
					$s = $loop[scalar(@loop) - 1];
47
				}
48-
			else {
48+
				else {
49-
				pop @loop;
49+
					pop @loop;
50
				}
51
			}
52
		}
53
	
54
}
55
print "\n";