Hi,
The Euclidean metric ( sqrt(a^2+b^2+c^2) ) does not approximate perceived color distance very well. In my version of this project (this seems to be one of these weird wheels everybody keeps reinventing^^) I used the LUV color space, where the Euclidean metric gives somewhat better (though still imperfect) results.
Also, using the ANSI standard palette (colors 0-16) is unwise for image display since users tend to re-define these colors using color themes in their terminal emulators.
Cheers,
jaseg