[math-fun] Stupid digital question
Let b >= 2, n >= 0. Let f(n,b) be the smallest nonnegative base-b numeral whose digital product is n. The value of f(b,0) and f(b,1) depend on whether we use the standard base-b representation of 0 ("0") or the purist representation ("", the null string). In the form case f(b,0) = "0" and f(b,1) = "1" while in the latter f(b,0) = "10" and f(b,1) = "" (whose digital product is technically 1). Either way, f(b,0) and f(b,1) are easy to compute and prove. The values of f(b,n) for n >= 2 are unaffected by this choice of representation. My stupid question is about computing f(b,n). In a recent program, I used the following algorithm: // Return the smallest base-b numeral whose digital product is n, or "-" if no such numeral. // Assumes purist base-b representation for simplicity function f(integer n, integer b) { // Handle zero if (n == 0) return "10"; // Start with null numeral numeral = ""; // For each base-b digit starting at the largest down to 2 for (integer digitValue = b-1; digitValue >= 2; digitValue--) { // While this digit divides n while (n%digitValue == 0) { // Divide digit out of n n /= digitValue; // Prepend base-b digit to numeral numeral = digit(digitValue, b) || numeral; } } // If n has factors that are not base-b digits, it is not a digital product if (n > 1) return "-"; // Return the numeral we built return numeral; } In effect, I went through the base-b digits in reverse order, each time dividing n by the digit as many times as possible, and took the dividing digits in reverse order as the ostensible smallest number with digital product n. Modulo probable errors in this hand-written pseudocode, is this algorithm correct? Does it actually return the smallest base-b numeral with digital product n? If so, how do we prove this? If not, does it work for some bases and not for others? Which bases does it work for? Does it work for base 10, as suggested by empirical testing I have done?
That algorithm fails for base 9, product 216. It produces 3338, but 666 is the answer. -- Don Reble djr@nk.ca -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Thanks, you have confirmed by doubts. Is it good for base 10? What bases is it good for? ----- Original Message ----- From: "Don Reble" <djr@nk.ca> To: "math-fun" <math-fun@mailman.xmission.com> Sent: Thursday, May 17, 2007 3:13 AM Subject: Re: [math-fun] Stupid digital question
That algorithm fails for base 9, product 216. It produces 3338, but 666 is the answer. -- Don Reble djr@nk.ca
Your greedy digital product algorithm fails for bases b = 9 and b > 16. A family of counterexamples n = 2^k.p^k where p is the greatest prime < 2^(k-1) fails for bases b in 1+2^k .. p^2 gives examples for all b > 16. I suspect your greedy algorithm works for all b < 17 except b = 9. - Scott
Thanks, you have confirmed by doubts.
Is it good for base 10?
What bases is it good for?
----- Original Message ----- From: "Don Reble" <djr@nk.ca> To: "math-fun" <math-fun@mailman.xmission.com> Sent: Thursday, May 17, 2007 3:13 AM Subject: Re: [math-fun] Stupid digital question
That algorithm fails for base 9, product 216. It produces 3338, but 666 is the answer. -- Don Reble djr@nk.ca
_______________________________________________ math-fun mailing list math-fun@mailman.xmission.com http://mailman.xmission.com/cgi-bin/mailman/listinfo/math-fun
participants (3)
-
David Wilson -
Don Reble -
Scott Huddleston