Skip to main content
added 109 characters in body
Source Link

Bash + OS X (BSD) utilities, 2424 22 bytes

Thanks to @seshoumara for saving 2 bytes.

seq 0 $1|tr$1|fold -d \\n|wc1|wc -cl

Test runs on Mac OS X:

$ for n in 8 101 102 -10 -1 0 1; do printf %6d $n; ./digitcount $n; done
     8       9
   101     196
   102     199
   -10      22
    -1       3
     0       1
     1       2

Here's a GNU version:

Bash + coreutils, 4040 38 bytes

Again, 2 bytes saved thanks to @seshoumara.

(seq $1 0;seq 0 $1)|uniq|tr|uniq|fold -d \\n|wc1|wc -cl

Try it online!Try it online!

Bash + OS X (BSD) utilities, 24 bytes

seq 0 $1|tr -d \\n|wc -c

Test runs on Mac OS X:

$ for n in 8 101 102 -10 -1 0 1; do printf %6d $n; ./digitcount $n; done
     8       9
   101     196
   102     199
   -10      22
    -1       3
     0       1
     1       2

Here's a GNU version:

Bash + coreutils, 40 bytes

(seq $1 0;seq 0 $1)|uniq|tr -d \\n|wc -c

Try it online!

Bash + OS X (BSD) utilities, 24 22 bytes

Thanks to @seshoumara for saving 2 bytes.

seq 0 $1|fold -1|wc -l

Test runs on Mac OS X:

$ for n in 8 101 102 -10 -1 0 1; do printf %6d $n; ./digitcount $n; done
     8       9
   101     196
   102     199
   -10      22
    -1       3
     0       1
     1       2

Here's a GNU version:

Bash + coreutils, 40 38 bytes

Again, 2 bytes saved thanks to @seshoumara.

(seq $1 0;seq 0 $1)|uniq|fold -1|wc -l

Try it online!

added 338 characters in body
Source Link

Bash + OS X (BSD) utilities, 24 bytes

seq 0 $1|tr -d \\n|wc -c

Test runs on Mac OS X:

$ for n in 8 101 102 -10 -1 0 1; do printf %6d $n; ./digitcount $n; done
     8       9
   101     196
   102     199
   -10      22
    -1       3
     0       1
     1       2

Here's a GNU version:

Bash + coreutils, 40 bytes

(seq $1 0;seq 0 $1)|uniq|tr -d \\n|wc -c

Try it online!

Bash + OS X (BSD) utilities, 24 bytes

seq 0 $1|tr -d \\n|wc -c

Test runs on Mac OS X:

$ for n in 8 101 102 -10 -1 0 1; do printf %6d $n; ./digitcount $n; done
     8       9
   101     196
   102     199
   -10      22
    -1       3
     0       1
     1       2

Bash + OS X (BSD) utilities, 24 bytes

seq 0 $1|tr -d \\n|wc -c

Test runs on Mac OS X:

$ for n in 8 101 102 -10 -1 0 1; do printf %6d $n; ./digitcount $n; done
     8       9
   101     196
   102     199
   -10      22
    -1       3
     0       1
     1       2

Here's a GNU version:

Bash + coreutils, 40 bytes

(seq $1 0;seq 0 $1)|uniq|tr -d \\n|wc -c

Try it online!

added 250 characters in body
Source Link

Bash + OS X (BSD) utilities, 24 bytes

seq 0 $1|tr -d \\n|wc -c

Test runs on Mac OS X:

$ for n in 8 101 102 -10 -1 0 1; do printf %6d $n; ./digitcount $n; done
     8       9
   101     196
   102     199
   -10      22
    -1       3
     0       1
     1       2

Bash + OS X (BSD) utilities, 24 bytes

seq 0 $1|tr -d \\n|wc -c

Bash + OS X (BSD) utilities, 24 bytes

seq 0 $1|tr -d \\n|wc -c

Test runs on Mac OS X:

$ for n in 8 101 102 -10 -1 0 1; do printf %6d $n; ./digitcount $n; done
     8       9
   101     196
   102     199
   -10      22
    -1       3
     0       1
     1       2
added 4 characters in body
Source Link
Loading
Source Link
Loading