given the number 123456789, is it possible to find a permutation such that the l
ID: 3748343 • Letter: G
Question
given the number 123456789, is it possible to find a permutation such that the left most digit is evenly divisible by 1, the two left most digits are evenly divisible by 2, the three left most digits are divisibly by 3 and so on? For example, in 123456789, 1 is evenly divisible by 1, 12 is evenly divisible by 2, 123 is evenly divisible by 3, but because 1234 is not evenly divisible by 4 this number is not a solution to the question. Second, is it possible to find a similar permutation given the number 1234567890? Finally, is it possible to find a similar permutation for any of the given hexadecimal numbers, 1234567890AB, 1234567890ABC, 1234567890ABCD, 1234567890ABCDE, 1234567890ABCDEF?
Explanation / Answer
I .Yes, is it possible to find a permutation such that the left most digit is evenly divisible by 1, the two left most digits are evenly divisible by 2, the three left most digits are divisibly by 3 and so on by following a two step approach
1.Find all the possible permutations of the number using heap algorithm
Reference:https://www.geeksforgeeks.org/heaps-algorithm-for-generating-permutations/
2. For each permutaion generated,find the use a function that passes the digits sum and the number as argument eg for number= 123 and total_digit =3 ,this will recurvisely divide the number by 10 reducing the number and digits and return true if the entire number subset as divisible by corrosponding digits.The function will return true of the entire number set is divisibe by corrosponding digits.
Reference: Based on the language you could checkout-
https://www.geeksforgeeks.org/rearrangement-number-also-divisible/
II. For a hexadecimal number the above procedure can be implemented once the number has been converted into decimal.i.e step 1 and 2 should be preceded by conversion of hexadecimal number to decimal.
Reference:http://www.codingalpha.com/convert-hexadecimal-to-decimal-number-c-program/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.