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


Problem DescriptionAlmost every integer contains at least one occurrence of the digit 3! Prove this for yourself by counting how many contain a 3 for numbers up to 10, up to 100, 1000, 10,000, etc. Background and TechniquesI put 2 buttons on this program form called "The Dumb Way" and "The Smart Way" . "The Dumb Way" was to start counting inside a loop, converting each integer to a string, scanning the strings for 3's, and adding to a counter when the first 3 was found in each number. The smart way uses the following analysis: for integers up to 10 there is one number containing a 3 (10%), up to 100 there are 9 of these "sets of 10", (09, 1019, 2029, 4049, etc.) each containing a single 3, and one "set of 10" where each number has a 3 (3039) for a total of 19 (19%). Up to 1000 there are nine sets of 100 each containing 19 "3's" and one set containing 100 ( the "300's") for a total of 271 (27.1%). Are you starting to see a pattern here? (Try 10^{n}9^{n}.) The other Delphi thing you might learn from this program is he technique used here to arrange the display data into columns. There is a TListView component that supports columns, but in this case I wanted to put new column headings in the middle of the display for the :"Smart way" button. The algorithm used is to divide the listbox width by 4 and right align the data in each of the first 3. The routine AdjustListBoxText does this inserting spaces at the beginning of the each string until canvas.textwidth is the desired width. Running/Exploring the ProgramSuggestions for further explorationNot much Delphiwise, but if you're interested in large numbers... The idea of infinity is not an easy one to grasp. You can start to get an idea if you consider the claim that almost all integers contain, not just a "3", but all of the digits from "0" through "9" at least once. In fact most integers contain the sequence of digits "0123456789" at least once. In fact, most integers contain "0123456789" at least a thousand times! You've may have heard Bob Newhart's comedy skit about putting enough monkeys in front of typewriters and letting them work long enough to produce the complete works of Wm. Shakespeare. Since the number of rearrangements of the letters in Shakespeare's works is finite, the idea is true (in theory). If we assume Shakespeare's works contain 100,000 words and each word averages 5 characters then we have half a million character positions to fill. Let's assume that there are 35 choices for each  oh heck let's say 100 choices, we want the capitalization to be correct plus the numbers plus punctuation marks and spaces. So we have only 100^{500,000 }arrangements to try. Maybe only half that many before we hit up the correct one.^{ } This is a number between a google and a googleplex. A mere drop in the bucket in the world of large numbers. Try searches on infinity and googolplex to learn more about big. You can also search on "monkeys Shakespeare typewriters" and get at least one essay calculating the time required. (And a bunch of jokes that read like this: "We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true.") 
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 20002018, Gary Darby All rights reserved. 