Test whether the first input x is an n-parasitic number: http://en.wikipedia.org/wiki/Parasitic_number. ( n is the second input.)
parasitic(128205,4) ---> true
parasitic(179487,4) ---> true
parasitic(179487,3) ---> false
might be best to add a test case to guard against test suite hacking
Far too few test cases. In fact, a serious issue with this problem is that there are too few parasitic numbers that will fit into even 64 bits for most values of n.
I've added some test cases, that will make it a bit more difficult to game this problem.
Cases 5 and 7 are identical, and I believe they are both wrong. 5 x 142857 = 714285. Isn't this a parasitic number? What am I missing?
Can the problem creator disqualify "solutions" that cheat? There should be a point penalty (-200) associated with cheating too.
There is 4, not 5
I mis-typed. 4 x 142857 = 571428, which is a shift right of 2. Incidentally, both n = 4 and 5 both make parasitic pairs with 142857.
Thus it is not a 4-parasitic number. It doesn't meet the definition. Nevertheless is a great example of a cyclic number. You can get different cyclic permutations when multiply 142857 by 1, 2, 3, 4, 5 and 6. For 5 you got shift by one digit, therefore it's 5-parasitic.
Ahhh, I see! Thanks, Jan - I get it now!
Not actually a general solution. Takes advantage of limited test cases.
Stuff the Board
Cell Counting: How Many Draws?
Find the logic
kmph to mps
Tune your guitar
Cull vector elements that contain a specified digit
Factorize THIS, buddy
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office