Problem 60783. Convert integers from base 10 to proper primary notation
Solution Stats
Problem Comments
-
10 Comments
> However, proper primary notation has the smallest number of digits. So, while 5 can be expressed as pp, pxx, and pxxm, the proper primary notation is pp.
I think this isn't enough to ensure uniqueness: 12 could be pxpp (7 + 3 + 2), or ppxx (7 + 5), for instance.
And this also affects the test cases: -28734 and 153488 in particular, for which my WIP solution finds different proper primary notations, namely 'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmpmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm' and 'ppppppppppppppppppppppppppppppppppppppppppppxpppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppmppppp' respectively.
Thanks Christian. You're right that the current description doesn't ensure uniqueness. How about, "If m, x, and p, are switched to 0, 1, and 2, respectively, for positive n and 2, 1, and 0 for negative n, then the resulting base-10 number would be as small as possible."? Is there a less clumsy way to say that?
@Chris Yes. If you add this requirement, then you can in fact drop the first one, and just write (say) this:
"Because integers can be expressed as sums (and differences) of primes in several ways, several primary notations for a number can exist. To ensure uniqueness, we require that when 1 is added to the factors of the primes, (so that 'p' is replaced with 2, 'x' with 1 and 'm' with 0 in the primary notation), 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."
OK, thanks. I changed the description.
If I understand correctly, for n=-1800 the sorting rule m<x<p should give 'mmmmmmmmmmmmmmmmmmmmmmmmpmxmmmmm' rather than 'mmmmmmmmmmmmmmmmmxmmmmmmmmmmmmmp'; the test suite seems to use m<x<p for positive n, but p<x<m for negative n, so that the results for +n and -n always look the same but with m and p swapped.
I am passing all tests except test 11 (-28734). I am getting a solution of:
'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmpmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm' which is a smaller integer than your solution:
'mmmmmmmxmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmxmm'.
I changed the problem to deal with non-negative numbers.
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.
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!