Problem 1130. Challenging perms function!
This problem is highly related with Problem 1127.
In oder to encrypt the word 'go' using phone keyboard, we need to do these;
- first find the digits that includes the letters in word. For example letter 'g' takes place on key 4. Letter 'o' is on key 6. So first number is 46.
- create all string permutations using the letters on keys (4 and 6). There are 'ghi' letters on key 4 and 'mno' letters on key 6. All two letter permutation list is {'gm';'gn';'go';'hm';'hn';'ho';'im';'in';'io'}. In this list third one is 'go'. So second number must be 3.
If input is 'go'; output must be [46 3].
What about 'hydroglycerin'? it is 1679616 th word on the permutation list constructed using keys 4937645923746.
If input is 'hydroglycerin'; output must be [4937645923746 1679616].
Given a string, return the keys on phone-keyboard and the order of this string in permutation list!
Solution Stats
Problem Comments
-
3 Comments
The test set gives a false impression as to Matlab's large number precision. For the case of x = 'antidisestablishmentarianism';
y_correct = [2684347378225474636827426476 13474859120710];
The eps(2684347378225474636827426476) is 5.4976e+11. An input of 'antidisestablishmentarianist' will return y_correct = [2684347378225474636827426478 13474859120710]; However, the ism y_correct would score the ist correct as Matlab cannot distinguish the two huge values. A vector output of the first part is one method to get unique solutions. A second method would require uint64 and having multiple values. I like the pairing of encryption and decryption challenges.
Nice Challenge.
I understand. Thanks for the comment.
Mehmet, what Richard tried to say is that 2684347378225474636827426476 is a number greater than 2^64-1, the highest unsigned integer number that MATLAB can store with precision (which means storing this number in double will make it loose its less significant digits). Therefore, the 5th case cannot be compared exactly with the function isequal. You must use some tolerance when comparing such numbers, abs(x-y) < tol, or use characters for an exact solution, like '2684347378225474636827426476'.
PS: And any solutions generating this number by any means are not correct at all, inclunding mine. We are all trying to store 3GB in a 2GB pendrive, it will not store everything.
Solution Comments
Show commentsProblem Recent Solvers10
Suggested Problems
-
101378 Solvers
-
Back to basics 17 - white space
271 Solvers
-
216 Solvers
-
Get ranks of values in a vector
52 Solvers
-
How long do each of the stages of the rocket take to burn?
302 Solvers
More from this Author92
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!