This problem is the next step up from Problem 156. Rather than determining if an input is a parasitic number, you will be asked to generate one. You will be given the last digit of the number (k), and the number you're using to multiply to shift the parasitic number one digit (n). Both n and k will always be between 1 and 9.
For example, if n=4 and k=7:
4x7=2*8*
4x87=3*48*
4x487=1*948*
4x9487=3*7948*
4x79487=3*17948*
4x179487=717948.
So 179487 is a 4-parasitic number with units digit 7.
We are looking for the smallest possible number that meets these criteria, so while 179487, 179487179487, and 179487179487179487 are all valid answers for n=4 and k=7, the correct output for this function is 179487.
Because some of the values that are generated by this function are very large, the output should be a string rather than an integer. Please bear in mind that some of these values will have leading zeros. This will occur when n>k.
Solution Stats
Problem Comments
3 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers95
Suggested Problems
-
Find the alphabetic word product
3456 Solvers
-
Get the area codes from a list of phone numbers
1071 Solvers
-
Back to basics 21 - Matrix replicating
1788 Solvers
-
Implement simple rotation cypher
1095 Solvers
-
Sum the numbers on the main diagonal
611 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
As per the wiki page provided in problem 156 "leading zeros are not allowed". Thus the solution set here is flawed.
Chris, you are correct. The definition of a parasitic number does state "No Leading Zeros." That's why I explicitly stated that some of these values would have a leading zero, and when they would occur. While these numbers are technically not parasitic, the method for generating them is the same.
My solution works ok from the scratchpad, but only test 6 passes. I put my scratchpad inputs in Solution 8750070. I copied the y_correct values from the test cases, and all te isequal calls return true. Any idea why they fail, and why test 6 passes?