Perl, 32 + 32 = 64
String diharapkan di STDIN. Outputnya ditulis ke STDOUT. Ruang putih diabaikan. Interpretasi saya terhadap tugas ini adalah bahwa program harus dapat berjalan sendiri untuk mendapatkan skor.
$/ = $,;
$_ = <>;
s x\sxxg;
$\ = length;
print s x[0-9a-z]xxgi,
' + ',
s x.xxg,
' = '
Tidak dikoleksi dengan komentar
$/ = $,; # 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.
' = '
Saya menemukan beberapa variasi dengan jumlah byte yang sama, misalnya:
$/ = $x;
$_ = <>, s x\sxxg;
$\ = split $x;
print s x[\da-z]xxgi,
" + ",
s x.xxg,
' = '
Contohnya
Contoh dari pertanyaan:
echo 'http://stackexchange.com' | perl a.pl
20 + 4 = 24
Berjalan dengan sendirinya ( a.pl):
cat a.pl | perl a.pl
32 + 32 = 64
Ukuran file adalah 104 byte, sehingga 40 byte diabaikan sebagai ruang putih.
Perl, 29 + 29 = 58
$_=<>;s x\sxxg;$\=length;print s x[0-9a-z]xxgi,' + ',s/.//g,' = '
String diharapkan pada STDIN dan terbatas pada baris pertama. Hasilnya dicetak ke STDOUT. Ruang putih diabaikan.
Tidak disatukan
$_ = <>;
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
' = '
Contohnya
File a.plberisi skrip Perl.
Contoh dari pertanyaan:
echo 'http://stackexchange.com' | perl a.pl
20 + 4 = 24
Berjalan dengan sendirinya:
cat a.pl | perl a.pl
29 + 29 = 58
Ukuran file a.pladalah 65 byte, sehingga 7 byte diabaikan sebagai ruang putih.
O.,O?danO!kemudian setiap program yang saya tulis memenuhi pembatasan kelas karakter ... Tentu saja ada kemungkinan kehilangan pada bisnis panjang.