Skip to main content
added 55 characters in body
Source Link
Kenney
  • 956
  • 4
  • 4

Perl, 71 6262 61 bytes

includes +1 for -n

$;=length($b+=y///c;$w+=split$"c);$w+=split$"}{$;=length$b;printf"%$;dprintf"%$;d %$;d $b",$.,$w

Commented:

while (<>) {                         # implicit because of -n
    $b$; +== y///c;length(                     # countprintf charactersformatting: width
    $w += split $"$b += y///c                   # count wordscharacters
}{    );
    $w += split $"                   # count words
}{    # explicit: end while, begin END block
    $; = length $b;                  # prepareexplicit: printfend formattingwhile, withbegin barewordEND block
    printf "%$;d %$;d $b", $., $w    #  $. = $INPUT_LINE_NUMBER
}                                    # implicit because of -n
  • Save another byte, again thanks to @TonHospel.
  • Save 9 bytes thanks to @TonHospel showing me a few tricks of the trade!

Perl, 71 62 bytes

includes +1 for -n

$b+=y///c;$w+=split$"}{$;=length$b;printf"%$;d %$;d $b",$.,$w

Commented:

while (<>) {                         # implicit because of -n
    $b += y///c;                     # count characters
    $w += split $"                   # count words
}{                                   # explicit: end while, begin END block
    $; = length $b;                  # prepare printf formatting, with bareword
    printf "%$;d %$;d $b", $., $w    #  $. = $INPUT_LINE_NUMBER
}                                    # implicit because of -n
  • Save 9 bytes thanks to @TonHospel showing me a few tricks of the trade!

Perl, 71 62 61 bytes

includes +1 for -n

$;=length($b+=y///c);$w+=split$"}{printf"%$;d %$;d $b",$.,$w

Commented:

while (<>) {                         # implicit because of -n
    $; = length(                     # printf formatting: width
       $b += y///c                   # count characters
    );
    $w += split $"                   # count words
}{                                   # explicit: end while, begin END block
    printf "%$;d %$;d $b", $., $w    #  $. = $INPUT_LINE_NUMBER
}                                    # implicit because of -n
  • Save another byte, again thanks to @TonHospel.
  • Save 9 bytes thanks to @TonHospel showing me a few tricks of the trade!
added 65 characters in body
Source Link
Kenney
  • 956
  • 4
  • 4

Perl, 7171 62 bytes

includes +1 for -pn

$b+=length;$w+=@x=$b+=y/\S+/g/c;$w+=split$"}{$W=length($b).d;$_=sprintf"%$W$;=length$b;printf"%$;d %$W%$;d $b",$.,$w

Commented:

while (<>) {                         # implicit because of -pn
    $b += length;y///c;                     # count characters
    $w += @xsplit =$" /\S+/g                  # count words
}{                                   # explicit: end while, begin END block
    $W$; = length($b) .$b; d;                 # prepare printf formatting, with bareword
    $_ = sprintfprintf "%$W"%$;d %$W%$;d $b", $., $w  # set output;#  $. = $INPUT_LINE_NUMBER
}                                    # implicit because of -pn
  • Save 9 bytes thanks to @TonHospel showing me a few tricks of the trade!

Perl, 71 bytes

includes +1 for -p

$b+=length;$w+=@x=/\S+/g}{$W=length($b).d;$_=sprintf"%$W %$W $b",$.,$w

Commented:

while (<>) {                         # implicit because of -p
    $b += length;                    # count characters
    $w += @x = /\S+/g                # count words
}{                                   # explicit: end while, begin END block
    $W = length($b) . d;             # prepare printf formatting, with bareword
    $_ = sprintf "%$W %$W $b",$.,$w  # set output; $. = $INPUT_LINE_NUMBER
}                                    # implicit because of -p

Perl, 71 62 bytes

includes +1 for -n

$b+=y///c;$w+=split$"}{$;=length$b;printf"%$;d %$;d $b",$.,$w

Commented:

while (<>) {                         # implicit because of -n
    $b += y///c;                     # count characters
    $w += split $"                   # count words
}{                                   # explicit: end while, begin END block
    $; = length $b;                  # prepare printf formatting, with bareword
    printf "%$;d %$;d $b", $., $w    #  $. = $INPUT_LINE_NUMBER
}                                    # implicit because of -n
  • Save 9 bytes thanks to @TonHospel showing me a few tricks of the trade!
Source Link
Kenney
  • 956
  • 4
  • 4

Perl, 71 bytes

includes +1 for -p

$b+=length;$w+=@x=/\S+/g}{$W=length($b).d;$_=sprintf"%$W %$W $b",$.,$w

Commented:

while (<>) {                         # implicit because of -p
    $b += length;                    # count characters
    $w += @x = /\S+/g                # count words
}{                                   # explicit: end while, begin END block
    $W = length($b) . d;             # prepare printf formatting, with bareword
    $_ = sprintf "%$W %$W $b",$.,$w  # set output; $. = $INPUT_LINE_NUMBER
}                                    # implicit because of -p