3 ms·
Take all the source code. Compress it using your best compression algorithm. The larger the size of the resulting file, the higher the complexity. Basically en
by trashtester 4y ago
Take all the source code. Compress it using your best compression algorithm. The larger the size of the resulting file, the higher the complexity.
Basically entropy.
Now, if you can write another program that does the same, but can be compressed to a much smaller file, it is likely to have a more elegant approach. (Especially if both use the same language and style guide).
Another factor to consider, though, is the compression factor of a program. The more a program is compressed, the more repetitive it's likely to be. Such code tends to have less real complexity, even if it may look complex at first glance.