line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::Beatnik; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
9259
|
use Filter::Simple; |
|
1
|
|
|
|
|
89975
|
|
|
1
|
|
|
|
|
9
|
|
4
|
1
|
|
|
1
|
|
62
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
5
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION $ip @stack @numbers %reftable %scrabble $debug); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
18756
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$debug = 0; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
%reftable = |
10
|
|
|
|
|
|
|
(5, \&_push, |
11
|
|
|
|
|
|
|
6, \&_pop, |
12
|
|
|
|
|
|
|
7, \&_add, |
13
|
|
|
|
|
|
|
8, \&_input, |
14
|
|
|
|
|
|
|
9, \&_output, |
15
|
|
|
|
|
|
|
10, \&_subtract, |
16
|
|
|
|
|
|
|
11, \&_swap, |
17
|
|
|
|
|
|
|
12, \&_duplicate, |
18
|
|
|
|
|
|
|
13, \&_jump_forward_if_zero, |
19
|
|
|
|
|
|
|
14, \&_jump_forward_if_not_zero, |
20
|
|
|
|
|
|
|
15, \&_jump_back_if_zero, |
21
|
|
|
|
|
|
|
16, \&_jump_back_if_not_zero, |
22
|
|
|
|
|
|
|
17, \&_halt |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
%scrabble = |
26
|
|
|
|
|
|
|
('A',1,'B',3,'C',3,'D',2,'E',1,'F',4,'G',2,'H',4,'I',1,'J',8,'K',5,'L',1,'M',3,'N',1,'O',1,'P',3,'Q',10,'R',1,'S',1,'T',1,'U',1,'V',4,'W',4,'X',8,'Y',4,'Z',10); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$VERSION = '0.02'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _push |
31
|
55
|
|
|
55
|
|
57
|
{ $ip++; |
32
|
55
|
50
|
|
|
|
92
|
print "pushing $numbers[$ip]\n" if $debug; |
33
|
55
|
|
|
|
|
145
|
push(@stack,$numbers[$ip]); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _pop |
37
|
0
|
|
|
0
|
|
0
|
{ my $foo = pop @stack; |
38
|
0
|
0
|
|
|
|
0
|
print "popping $foo\n" if $debug; |
39
|
0
|
|
|
|
|
0
|
return $foo; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _add |
43
|
55
|
|
|
55
|
|
83
|
{ my($first,$second) = (pop @stack,pop @stack); |
44
|
55
|
|
|
|
|
65
|
my $sum = $first + $second; |
45
|
55
|
|
|
|
|
78
|
push(@stack,$sum); |
46
|
55
|
50
|
|
|
|
180
|
print "adding $first and $second and pushing $sum on stack \n" if $debug; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _input |
50
|
0
|
0
|
|
0
|
|
0
|
{ print "accepting user input and pushing onto stack\n" if $debug; |
51
|
0
|
|
|
|
|
0
|
push(@stack,ord(getc)); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _output |
55
|
12
|
|
|
12
|
|
17
|
{ my $foo = pop @stack; |
56
|
12
|
50
|
|
|
|
27
|
print "outputting ",chr($foo),"\n" if $debug; |
57
|
12
|
|
|
|
|
51
|
print(chr($foo)); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _subtract |
61
|
0
|
|
|
0
|
|
0
|
{ my ($first,$second) = (pop @stack,pop @stack); |
62
|
0
|
|
|
|
|
0
|
my $diff = $first - $second; |
63
|
0
|
0
|
|
|
|
0
|
print "subtraction $first and $second and pushing $diff on stack\n" if $debug; |
64
|
0
|
|
|
|
|
0
|
push(@stack,$diff) |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _swap |
68
|
0
|
|
|
0
|
|
0
|
{ my $a = pop(@stack); |
69
|
0
|
|
|
|
|
0
|
my $b = pop(@stack); |
70
|
0
|
0
|
|
|
|
0
|
print "swapping $a and $b\n"if $debug; |
71
|
0
|
|
|
|
|
0
|
push(@stack,$a,$b); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _duplicate |
75
|
0
|
0
|
|
0
|
|
0
|
{ print "duplicating $stack[$#stack]\n" if $debug; |
76
|
0
|
|
|
|
|
0
|
push(@stack,$stack[$#stack]); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _jump_forward_if_zero |
80
|
0
|
|
|
0
|
|
0
|
{ my $n = pop(@stack); |
81
|
0
|
|
|
|
|
0
|
$ip++; |
82
|
0
|
0
|
|
|
|
0
|
if($n == 0) |
83
|
0
|
0
|
|
|
|
0
|
{ $ip += $numbers[$ip]; print "jump $n words forward\n" if $debug; } |
|
0
|
|
|
|
|
0
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _jump_forward_if_not_zero |
87
|
0
|
|
|
0
|
|
0
|
{ my $n = pop(@stack); |
88
|
0
|
|
|
|
|
0
|
$ip++; |
89
|
0
|
0
|
|
|
|
0
|
if($n != 0) |
90
|
0
|
0
|
|
|
|
0
|
{ $ip += $numbers[$ip]; print "jump $n words forward\n" if $debug; } |
|
0
|
|
|
|
|
0
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _jump_back_if_zero |
94
|
0
|
|
|
0
|
|
0
|
{ my $n = pop(@stack); |
95
|
0
|
|
|
|
|
0
|
$ip++; |
96
|
0
|
0
|
|
|
|
0
|
if($n == 0) { $ip -= $numbers[$ip]; print "jump $n words backward\n" if $debug; } |
|
0
|
0
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _jump_back_if_not_zero |
100
|
0
|
|
|
0
|
|
0
|
{ my $n = pop(@stack); |
101
|
0
|
|
|
|
|
0
|
$ip++; |
102
|
0
|
0
|
|
|
|
0
|
if($n != 0) { $ip -= $numbers[$ip]; print "jump $n words backward\n" if $debug; } |
|
0
|
0
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _halt |
106
|
1
|
|
|
1
|
|
3
|
{ $ip = $#numbers+1; |
107
|
1
|
50
|
|
|
|
5
|
print "halting...\n" if $debug; |
108
|
1
|
|
|
|
|
1353
|
exit; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
FILTER |
112
|
|
|
|
|
|
|
{ $_ =~ s/[^\w\s]//g; |
113
|
|
|
|
|
|
|
my @words = split(/\s+/,$_); |
114
|
|
|
|
|
|
|
for my $word (@words) |
115
|
|
|
|
|
|
|
{ my $number = 0; |
116
|
|
|
|
|
|
|
for(split(//,$word)) |
117
|
|
|
|
|
|
|
{ $number += $scrabble{uc $_}; } |
118
|
|
|
|
|
|
|
push(@numbers,$number); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
for($ip = 0; $ip <= $#numbers ; $ip++) |
121
|
|
|
|
|
|
|
{ if (exists( $reftable{$numbers[$ip]} ) ) |
122
|
|
|
|
|
|
|
{ &{ $reftable{$numbers[$ip]} }; } |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
__END__ |