A vampire number is a number v that is the product of two numbers x and y such that the following conditions are satisfied:
- at most one of x and y are divisible by 10;
- x and y have the same number of digits; and
- The digits in v consist of the digits of x and y (including anyrepetitions).
If these conditions are met, x and y are known as "fangs" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.
Write a function that returns all the pairs of fangs for a given number. The output is a matrix in which each row is a pair; the values in the first row should be in increasing order. If it is not a vampire number, it will return empty arrays.
Example:
disp(vampire_factor(125460))
204 615
246 510
Solution Stats
Problem Comments
2 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers76
Suggested Problems
-
7235 Solvers
-
498 Solvers
-
346 Solvers
-
Convert a Cell Array into an Array
2186 Solvers
-
Given a square and a circle, please decide whether the square covers more area.
1712 Solvers
More from this Author9
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Test 5 seems to be incorrect.
125460 and 125500 are vampire numbers.
125460 = 204*615 = 246*510.
125500 = 251*500.
You are right, @DH.
Numbers generated through randi([imin imax]) syntax includes both the end values.
I have corrected the test case.