Why can't computers learn to count?

When a computer is sorting numbers, e.g. files with numerical names, it puts them in the order of:

1, 10-19, 2, 20-29, 3, etc., unless we give everything the same number of digits, by adding initial zeros.

Why can’t the computer look to see how many digits a number has, and understand that 2 is not between 19 and 20? A child’s brain is able to do this with very little instruction, why can’t a computer?

It can, you ust need to program it to.

Sounds very much as if the numbers you’re describing are stored in a text/string format; this would still sort correctly if you make sure that they are all the same length (in terms of digits):

1,10,11,12,13,14,15,16,17,18,19,2,20,21…

Would sort correctly if you add leading zeroes to the single-digit numbers:

01,02,03,04,05,06,07,08,09,10,11…

This is because string sorting works in strict sequence of digits without comprehending the numeric value (or even noticing that there is a number there - it is all based solely on characters.

It has nothing to do with the computer, all of which are really quite good at counting, and everything to do with the program doing the sorting. The above is an example of an alphabetical sort, wherein the numbers are treated as characters in a string. Just as all words starting with ‘a’ would be grouped together, so are all numbers starting with ‘1’. If you want to get around this, replace the sorting algorithm with one more to your liking, or make the numbers of universal width by adding leading zeroes.

I’m actually quite surprised that Windows XP doesn’t implement a numerical sorting method for filenames that are entirely composed of numerical digits - it is exactly the sort of enhancement I’d have expected.

The only way for the computer to know whether you want to sort numerically versus alphabetically is to define the field as a number or a string. Just because the filename is made up all numbers doesn’t mean that I want it sorted numerically.

Do you understand the difference between a numeric field and an alphanumeric string? Like in a spreadsheet? The fact that an alphanumeric field only contains the digits 0-9 does not make it numeric. A file name is alphanumeric and is correctly sorted as alphanumeric. A child’s brain can understand this too once it is explained to him.

Windows Explorer on Windows XP does in fact sort numbers correctly, furthermore it allows to you rename files en-masse (select more than 1 file and choose to rename it) and XP automatically generates numbering (i.e. myfile (1), myfile (2), etc.) and can sort them in correct order to boot!