27
\$\begingroup\$

Challenge

Given an integer \$Q\$ in the range \$-2^{100} ≤ Q ≤ 2^{100}\$, output the number of digits in that number (in base 10).

Rules

Yes, you may take the number as a string and find its length.

All mathematical functions are allowed.

You may take input in any base, but the output must be the length of the number in base 10.

Do not count the minus sign for negative numbers. The number will never have a decimal point.

Zero can either have one or zero digits.

Assume the input will always be a valid integer.

Examples

Input > Output

-45 > 2
12548026 > 8
33107638153846291829 > 20
-20000 > 5
0 > 1 or 0

Winning

Shortest code in bytes wins.

\$\endgroup\$
0

66 Answers 66

1 2
3
0
\$\begingroup\$

JavaScript, 23 bytes

x=>`${x<0?-x:x}`.length
\$\endgroup\$
0
\$\begingroup\$

Bound, 4 bytes

ib_,

Explanation:

i # Get user input
b # Separate each digit of the top element into individual elements
_ # Put the total number of elements onto the stack
, # Remove all but the top element from the stack

Bound then prints the stack at the end of execution, so you can then see the result.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

BRASCA, 15 bytes

iM:45S=[xx0]x!n

Try it online!

Explanation

i                - Turn the ascii characters 0-9 to numbers
 M:45S=[  0]     - Move the bottom of the stack to the front and check if it's a minus
        xx       - If so: remove the minus
            x    - Remove any excess items on the stack
             !n  - Print the length as a number
\$\endgroup\$
0
\$\begingroup\$

Whispers v2, 39 bytes

> Input
>> |1|
>> "2"
>> #3
>> Output 4

Try it online!

Boring answer. Get input, absolute value, convert to string, return length.

\$\endgroup\$
0
\$\begingroup\$

Arn -s, 2 bytes

.|

Try it!

Take absolute value, -s takes size. Implicit casting.

\$\endgroup\$
0
\$\begingroup\$

Julia, 7 bytes

ndigits

Try it online!

\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.