Recurring Quotient

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

 

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa® 365 Puzzlers  Calendar 2017

Mensa® 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

 

Beginner - Recurring Quotient

Program Description

If 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

If you divide a 5 digit number by the sum of its digits, some divide evenly, some do not.  For all 5 digit number between 10,000 and 99,999 that do divide evenly by the sum of their digits, what quotient occurs most often?

Source: Math and Logic Puzzles for PC Enthusiasts, J. J. Clessa, Dover Books.

Defining the program

Here'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 Program

To download executable click here:

To download source code, click here.

Suggestions for further exploration

I 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 © 2000-2018, Gary Darby    All rights reserved.