3 ms·
It absolutely is important to learn the long division algorithm for programming. How else do you deal with integer division? (Yes, integer division, which peo
by betterunix 13y ago
It absolutely is important to learn the long division algorithm for programming. How else do you deal with integer division?
(Yes, integer division, which people refer to as "big number" division for some bizarre reason.)
- deleted 13y ago[deleted]
- redblacktree 13y ago$ python >>> 523 / 6 87 >>> I can't remember any time when I've been called upon to write an algorithm for integer division.
- betterunix 13y ago1. Perhaps you should start now, since your Python interpreter gave you the wrong answer. It should be obvious that 523/6 is not an integer. 2. That is kind of like saying, "I can't remember any time when I have been called upon to implement merge sort, therefore there is no point in teaching the algorithm!!"
- redblacktree 13y agoIt's not wrong it's just the result of integer division where the remainder has been dropped. What makes you say it is "wrong?" Were you expecting a floating-point result? To your point #2, you didn't argue that teaching these concepts aids in the general understanding of how to create algorithms, you said, "How else do you deal with integer division?" To which my answer is: You don't. It's a solved problem.
- betterunix 13y agoI would expect either a pair of integers, either a rational number or a quotient and remainder. 523/6 is not 87. As for "solved problems," it is not at all unusual to be asked to re-implement an algorithm that is already implemented elsewhere. Maybe there is no implementation for your platform. Maybe you are writing a new language. You could find yourself implementing integer division just as much as you could find yourself implementing a sorting algorithm, a hash table, etc. [Edit: Also worth noting is that in the context of education it is common to ask students to re-implement known algorithms and build up systems on their own.]
- redblacktree 13y agoIn the context of education, I agree, but you strech credulity with this: > Maybe there is no implementation for your platform. I challenge you to find me a single example of a platform that does not already have an implementation for integer division. This functionality is basic. Edit: Also, you seem to have strange expectations with respect to results of integer division. Many languages in common use will give the result above. If you want the remainder, you're expected to use modulus. For example: >>> '%s %s/%s' % (523 / 6, 523 % 6, 523) '87 1/523' >>>