zlacker

[parent] [thread] 8 comments
1. nicbou+(OP)[view] [source] 2024-06-06 05:39:07
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.
replies(3): >>bittum+j >>_xnmw+s2 >>qwerty+66
2. bittum+j[view] [source] 2024-06-06 05:41:54
>>nicbou+(OP)
At the bottom of the article they mention that this was discouraged because they hadn't covered strings in the course yet
replies(1): >>MrJohz+E
◧◩
3. MrJohz+E[view] [source] [discussion] 2024-06-06 05:46:22
>>bittum+j
And more importantly, because it sidesteps the interesting pedagogy around edge cases and testing that the instructor is interested in.
replies(1): >>vsnf+51
◧◩◪
4. vsnf+51[view] [source] [discussion] 2024-06-06 05:51:58
>>MrJohz+E
The correct solution here is to give credit for the problem to acknowledge genuine clever problem solving, and then offer extra credit for doing it the pedagogical way.
replies(1): >>MrJohz+i2
◧◩◪◨
5. MrJohz+i2[view] [source] [discussion] 2024-06-06 06:05:56
>>vsnf+51
There is no correct solution here. A classroom is not a test environment.

The goal is to learn, and the point of the exercises is to teach a specific concept. If a student finds a different way around the problem, that may show that they're already proficient in other skills, but they haven't necessarily learned the concept being taught in this class yet. A good instructor would probably acknowledge the solution, but add extra boundaries to the task to get the student to explore the problem in a way that lets them encounter the testing difficulties discussed here.

It's like smuggling a calculator into a class about mental maths strategies: you'll probably do very well in the final test, but you won't have learned anything!

6. _xnmw+s2[view] [source] 2024-06-06 06:07:32
>>nicbou+(OP)
Len() and str() are a loop under the hood.
replies(1): >>emidln+Y5
◧◩
7. emidln+Y5[view] [source] [discussion] 2024-06-06 06:37:50
>>_xnmw+s2
len() is an O(1) lookup of the stored length on the unicode/bytes object in Python.
8. qwerty+66[view] [source] 2024-06-06 06:39:20
>>nicbou+(OP)
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"
replies(1): >>smarkl+Ph
◧◩
9. smarkl+Ph[view] [source] [discussion] 2024-06-06 08:33:04
>>qwerty+66
assuming python
[go to top]