Perl, 32 + 32 = 64
Chuỗi dự kiến trong STDIN. Đầu ra được ghi vào STDOUT. Không gian màu trắng bị bỏ qua. Giải thích của tôi về nhiệm vụ là chương trình sẽ có thể tự chạy để lấy điểm.
$/ = $,;
$_ = <>;
s x\sxxg;
$\ = length;
print s x[0-9a-z]xxgi,
' + ',
s x.xxg,
' = '
Phản đối với ý kiến
$/ = $,; # The input separator becomes undefined, because the default for $, is "undef"
$_ = <>; # now $_ takes the whole file (STDIN) instead of the first line
s x\sxxg; # $_ =~ s/\s//g;
# white space is removed from $_
$\ = length; # The number of the other characters are put into $\,
# which is automatically printed the end of "print".
print s x[0-9a-z]xxgi, # s/[0-9a-z]//gi
# Remove alphanumeric characters and return their count
' + ',
s x.xxg, # s/.//g
# Remove the remaining special characters and return their count.
# "." does not catch new lines, but we have already
# removed white spaces including new lines.
' = '
Tôi đã tìm thấy một số biến thể có cùng số byte, ví dụ:
$/ = $x;
$_ = <>, s x\sxxg;
$\ = split $x;
print s x[\da-z]xxgi,
" + ",
s x.xxg,
' = '
Ví dụ
Ví dụ từ câu hỏi:
echo 'http://stackexchange.com' | perl a.pl
20 + 4 = 24
Chạy trên chính nó ( a.pl
):
cat a.pl | perl a.pl
32 + 32 = 64
Kích thước tệp là 104 byte, do đó 40 byte bị bỏ qua dưới dạng khoảng trắng.
Perl, 29 + 29 = 58
$_=<>;s x\sxxg;$\=length;print s x[0-9a-z]xxgi,' + ',s/.//g,' = '
Chuỗi dự kiến tại STDIN và nó được giới hạn ở dòng đầu tiên. Kết quả được in thành STDOUT. Không gian màu trắng bị bỏ qua.
Ung dung
$_ = <>;
s x\sxxg; # same as s/\s//gx; removes white space;
$\ = length($_); # sum is automatically appended at the end of print
print sx[0-9a-z]xxgi, # same as s/[0-9a-z]//gi;
# the number of alphanumeric characters
' + ',
s/.//g, # the number of the remaining special characters
' = '
Ví dụ
Tệp a.pl
chứa tập lệnh Perl.
Ví dụ từ câu hỏi:
echo 'http://stackexchange.com' | perl a.pl
20 + 4 = 24
Chạy trên chính nó:
cat a.pl | perl a.pl
29 + 29 = 58
Kích thước tệp a.pl
là 65 byte, do đó 7 byte bị bỏ qua dưới dạng khoảng trắng.
O.
,O?
vàO!
rồi bất kỳ chương trình tôi viết đáp ứng các hạn chế lớp nhân vật ... Tất nhiên nó có khả năng mất vào việc kinh doanh dài.