zlacker

[return to "My favorite programming problem to teach: Digit length (2019)"]
1. jcynix+Bo3[view] [source] 2024-06-06 08:01:57
>>equili+(OP)
Hmm, my solution would be to convert the number to a string and return its length. Easily done in Perl:

  perl -e 'print length 987654'
  6
Similarly easy in Lisp with either of write-to-string, prin1-to-string, and princ-to-string. I expect python to have some such built-in function too.
◧◩
2. quirin+up3[view] [source] 2024-06-06 08:14:17
>>jcynix+Bo3
It is mentioned at the end of the article. In Python it's as simple as len(str(x)).
[go to top]