zlacker

[return to "My favorite programming problem to teach: Digit length (2019)"]
1. nicbou+I93[view] [source] 2024-06-06 05:39:07
>>equili+(OP)
Wouldn't len(str(num)) be adequate here? This is a quite literal translation of what the code should be doing: measuring the length of the text representation of a number. The mathematical approach seems a little convoluted, although it serves the purpose of teaching a lesson.
◧◩
2. qwerty+Of3[view] [source] 2024-06-06 06:39:20
>>nicbou+I93
Be careful, doing str(num) requires python to convert the binary representation it has num stored as to a decimal. (C)Python implements a quadratic time change of basis algorithm. This is slow enough that now for very large inputs python will raise "ValueError: Exceeds the limit (4300 digits) for integer string conversion"
◧◩◪
3. smarkl+xr3[view] [source] 2024-06-06 08:33:04
>>qwerty+Of3
assuming python
[go to top]