zlacker

My Favorite Programming Problem to Teach: Digit Length

submitted by jstrie+(OP) on 2019-11-10 21:58:21 | 124 points 106 comments
[view article] [source] [go to bottom]

NOTE: showing posts with links only show all posts
17. keithn+vk[view] [source] 2019-11-11 02:38:28
>>jstrie+(OP)
quite funny reading HN articles sometimes. So...

I read https://www.netmeister.org/blog/cs-falsehoods.html which came from https://news.ycombinator.com/item?id=21500672 in the top HN articles at the moment

Item 27 of that list made me laugh when I read this article :)

◧◩◪◨⬒
30. talake+wt[view] [source] [discussion] 2019-11-11 04:59:09
>>lifthr+wl
No support for that in Sloane's. https://oeis.org/A000027
48. woadwa+7F[view] [source] 2019-11-11 08:06:01
>>jstrie+(OP)
This reminds me of something I enjoyed writing a couple of years ago. I’d decided to use the Damm checksum algorithm[1] for order numbers at work. Every implementation that I could find was turning the number into a string than then check summing it one character at a time. And that approach felt rather suboptimal. So, I decided to write a numeric implementation[2].

[1]: https://en.m.wikipedia.org/wiki/Damm_algorithm

[2]: https://github.com/jeethu/damm

◧◩◪
51. pd0wm+4G[view] [source] [discussion] 2019-11-11 08:26:12
>>userbi+xo
Funny fact: the python round implementation actually uses strings. https://github.com/python/cpython/blob/master/Objects/floato...
◧◩◪
60. netmon+hJ[view] [source] [discussion] 2019-11-11 09:17:12
>>coldte+zE
I understand what you say, but i think you are wrong. Assembly is closest to what a cpu actually does for REAL, so you are programming. When using Python or whatever any advanced language, you are less programming CPU and more relying and tons of layers from other's works which are basically created to never let you understand how to program a CPU. So peoples feels they are programming, while they are just integrating tons of library and set them to do something usefull (which is good too).

But if you want to teach programming, i would follow my path, and provide a deeper understanding at how to control a cpu and how it really works. In order to demystify computer and gives student a real experience of all the hidden works that are done with a 4 lines python code.

and for the fun side, guess why assembly is the second searched language on Stack overflow during weekend : https://stackoverflow.blog/2017/02/07/what-programming-langu...

i guess people are trying to have more fun on weekend than on boring office project during work days :)

And those numbers show a real interest about Assembly which is usually greatly discarded in any common CS teaching anywere. So teachers decides it's not interesting, while in fact most peoples search about it on weekend...I mean it illustrates a real issue here. May be understanding how to program a cpu at low level is something natural, that only scholar peoples cannot understand, therefore neglecting natural tendency of normal peoples to try to understand how things really work...

And for those really wanting to even dig deeper and understand what is a CPU, i strongly suggest looking for "from nand to tetris" https://www.nand2tetris.org/ wich basically start at nand logical gate, to the extent to create a full working cpu and programming it to play tetris.

◧◩◪◨
64. NightM+KK[view] [source] [discussion] 2019-11-11 09:37:16
>>ruroun+Bx
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.

◧◩◪
82. soVery+0b1[view] [source] [discussion] 2019-11-11 14:17:26
>>gnuvin+fe
Python uses a String conversion to implement rounding, so why not? :)

https://github.com/python/cpython/blob/master/Objects/floato...

[go to top]