164k views
2 votes
How to group numbers in list into groups of number of digits?

1 Answer

4 votes

This looks a lot more like a computer programming problem than a math problem.

If the numbers are integers, adding 1 to the integer part of the base-10 logarithm will tell you the number of digits the number has. (Be careful with 0.)

Once you have a list that associates a number of digits with the number, you can categorize by the number of digits.

In short, take a number from your input list, count its digits, then assign it to an output list according to the number of digits it has.

_____

Another way to do this is to sort your numbers, then identify the numbers less than 10 (1-digit), less than 100 (2-digits), less than 1000 (3-digits), and so on.

User Lakshitha Ruwan
by
7.7k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories