zlacker

[parent] [thread] 5 comments
1. ruroun+(OP)[view] [source] 2019-11-11 05:59:23
I think it is more of a math exercise solved via programming. Which is somehing I am not particularly fond of.

These crop up all the time in those online programming challenge things.

They are usually maths problems (e.g. Find the combined area of two partially intersecting squares based on their coordinates of a,b,c,d and w,x,y,z) where the solution is done via programming but most of the work is, in my opinion, figuring out the maths which is testing for the wrong thing.

replies(3): >>raegis+u9 >>NightM+9d >>dTal+QK2
2. raegis+u9[view] [source] 2019-11-11 08:46:37
>>ruroun+(OP)
Many things people consider "programming" but not mathematics are things we actually study in mathematics classes. They're just unaware.
3. NightM+9d[view] [source] 2019-11-11 09:37:16
>>ruroun+(OP)
This particular problem (number of digits in a number) is actually monumentally important for performance reasons for e.g. json generation. See https://m.facebook.com/notes/facebook-engineering/three-opti... for details.

That said, I do agree that as stated the problem is a toy. The problem statement could at least motivate the lack of string operations - i.e. pretend you’re the language designer and you’re tasked with implementing str(int) in C. Just saying “don’t do that” isn’t helpful. Gaining an understanding that nothing is magical is useful though.

replies(2): >>FabHK+6j >>gpdere+uE
◧◩
4. FabHK+6j[view] [source] [discussion] 2019-11-11 10:47:53
>>NightM+9d
That link has a very insightful discussion (and incidentally provides a nice fast correct solution, and use case, for the initial problem!).
◧◩
5. gpdere+uE[view] [source] [discussion] 2019-11-11 14:23:39
>>NightM+9d
Probably the students do not know about big O notation at this point, but requiring a solution that uses at most O(1) additional space would be enough. Then again, automatic bignums in python make it hard to evaluate the space complexity.
6. dTal+QK2[view] [source] 2019-11-12 10:46:42
>>ruroun+(OP)
It's not a math exercise. The problem is stringly - find the length of the string that conventionally represents the given number. The problem is that 0 is a special case, because we write something rather than nothing. Using len(str(n)) is the correct, idiomatic way to solve this. Consider what happens when the problem domain expands to include negative numbers...

Notice that all the straightforward solutions the author rejects, they reject because it fails on 0. Then, with the oh-so-clever log10 solution... surprise! They special-case 0. I'm not sure what the lesson here is supposed to be.

[go to top]