Problem 60783. Convert integers from base 10 to proper primary notation
This problem is the companion to Cody Problem 60782. The proper primary system of expressing non-negative numbers has three digits: m, x, and p, which correspond to -1, 0, and 1. The places in a proper primary number correspond to the prime numbers. For example, the number 6 would be ppm in proper primary notation because . Similarly, the number 20 would be ppxxp in proper primary notation.
Because integers can be expressed as sums (and differences) of primes in several ways, several primary notations for a non-negative number can exist. However, numbers in proper primary notation adhere to the following requirement: when m, x, and p are replaced with 0, 1, and 2, respectively, the resulting decimal number is minimal.
For instance, 5 can be represented as pp, pxx, and pxmm; since 22 is smaller than 211 or 2100, pp is the proper primary representation of 5. The number 12 can be represented as pxpp and ppxx; since 2122 is less than 2211, pxpp is the proper primary representation of 12. The number -15 can be represented as mmmx and mmxpx; since 1 is less than 121, mmmx is the proper primary representation of -15.
Write a function to convert non-negative integers in base 10 to proper primary notation.
Solution Stats
Problem Comments
-
10 Comments
Show
7 older comments
ChrisR
on 9 Jan 2025 at 1:10
I changed the problem to deal with non-negative numbers.
Tim
on 10 Jan 2025 at 0:50
Representing negative numbers by swapping all the m's and p's would make for a rather elegant feature of this system. Even so, I don't think the system as a whole will catch on sufficiently to supplant the decimal system, as old and tired as that may be.
ChrisR
on 10 Jan 2025 at 23:11
My code swaps m's and p's as you described. I also agree about the prospects for this number system. In any case, I wish you and others in the Cody community a happy new year and good health in pppppppppxpppppppppppppppppppppxpp.
Solution Comments
Show commentsProblem Recent Solvers3
Suggested Problems
More from this Author291
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!