Perl, 32 + 32 = 64
Ciąg oczekuje się w STDIN. Dane wyjściowe są zapisywane w STDOUT. Białe znaki są ignorowane. Moją interpretacją tego zadania jest to, że program powinien być w stanie uruchomić się na sobie, aby uzyskać wynik.
$/ = $,;
$_ = <>;
s x\sxxg;
$\ = length;
print s x[0-9a-z]xxgi,
' + ',
s x.xxg,
' = '
Niegolfowany z komentarzami
$/ = $,; # 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.
' = '
Znalazłem kilka odmian o tej samej liczbie bajtów, np .:
$/ = $x;
$_ = <>, s x\sxxg;
$\ = split $x;
print s x[\da-z]xxgi,
" + ",
s x.xxg,
' = '
Przykłady
Przykład z pytania:
echo 'http://stackexchange.com' | perl a.pl
20 + 4 = 24
Uruchamianie na sobie ( a.pl):
cat a.pl | perl a.pl
32 + 32 = 64
Rozmiar pliku to 104 bajty, dlatego 40 bajtów jest ignorowanych jako białe znaki.
Perl, 29 + 29 = 58
$_=<>;s x\sxxg;$\=length;print s x[0-9a-z]xxgi,' + ',s/.//g,' = '
Ciąg oczekuje się na STDIN i jest ograniczony do pierwszego wiersza. Wynik zostanie wydrukowany do STDOUT. Białe znaki są ignorowane.
Nie golfił
$_ = <>;
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
' = '
Przykłady
Plik a.plzawiera skrypt Perla.
Przykład z pytania:
echo 'http://stackexchange.com' | perl a.pl
20 + 4 = 24
Uruchamianie na sobie:
cat a.pl | perl a.pl
29 + 29 = 58
Rozmiar pliku a.plto 65 bajtów, dlatego 7 bajtów jest ignorowanych jako białe znaki.
O.,O?iO!czym każdy zapis Program I spełnia ograniczenia klasy znak ... Oczywiście, że jest prawdopodobne, aby stracić na działalności długości.