Convert integers from base 10 to proper primary notation - MATLAB Cody - MATLAB Central

Problem 60783. Convert integers from base 10 to proper primary notation

Difficulty:Rate
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 pxxm; 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

100.0% Correct | 0.0% Incorrect
Last Solution submitted on Jan 09, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
3
6

Problem Recent Solvers3

Suggested Problems

More from this Author304

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!