[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]


Beginner  Recurring QuotientProgram DescriptionIf you would just like to download the Recurring Quotient program, click here. If you’d like to learn more about the program, read on. Problem Statement
Defining the programHere's the plan  I'm pretty sure that the largest quotient will be 10,000 (when we divide 10,000 by 1). So let's just set up an array to hold each of the 10,000 possible counts of quotient occurrences. In other words, when we finish, Counts[100] will contain the number of times that the quotient 100 occurred, etc. Then all we have to do is scan this array for the largest value and display it. Now all we have to do is figure out how to extract the digits from a number, add them up and test if they divide the number evenly. One good way to do this is to use the mod operation which returns the remainder when one number is divider by another (mod stands for modulo). In this case, n mod 10 will return the lowest level (units position) digit of n. If we then divide n by 10 dropping any remainder, we can apply the mod function again and get the 10s digit, etc. Luckily the integer divide function div does exactly this  divides one integer by another and returns the integer part of the quotient. You will easily find the loop that accomplishes this in the source code. There are only 36 lines of user written code here! Running/Exploring the ProgramTo download executable click here: To download source code, click here. Suggestions for further explorationI was going to suggest expanding the program to answer the question for 6 digit numbers, but I'm not sure how I'd do it (or if it's practical to solve it at all). You probably won't have enough memory to hold counts for all quotients up to 1,000,000. If any one solves this or has ideas about how to approach it, let me know. Maybe only a small subset of all possible quotients ever satisfies the conditions. In that case, we could maintain an array of quotients and an array of counts and for each quotient, find it or add it to the quotients table and add 1 to the corresponding counts array location.

[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 20002017, Gary Darby All rights reserved. 