## 03 November 2015

### Printing the permutation of characters from a classical mobile phone One of the problems I recently faced.

Input: A set of numbers from a mobile keypad
Output: Print all the combinations of characters for that given number.

For example if the input is 26. Then possible outputs are am, an, ao, bm, bn, bo, cm, cn, co

Solution:

There are many ways to solve this problem. One is using a tree. Another way is to simply do it with recursion. I solved this using a linear approach. If you convert the problem from the text domain to number domain - it will seem very simple.

For example - if the input is something like ['abc', 'def', 'pqrs'] (transformed from digits 237). Then the output would have a simple rule - the first character should come from the first element, second from the second and so on. Writing in an incremental number form for the indexes, you would get:

0 0 0
0 0 1
0 0 2
0 0 3
0 1 0
0 1 1
0 1 2
....
2 2 3

That's it - problem solved. Programatically expressed it here
{"ft_lang_label":"__label__en","ft_lang_prob":0.8560206,"math_prob":0.9219861,"size":1825,"snap":"2021-43-2021-49","text_gpt3_token_len":492,"char_repetition_ratio":0.107633166,"word_repetition_ratio":0.95530725,"special_character_ratio":0.28,"punctuation_ratio":0.14975846,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97863215,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-25T13:33:38Z\",\"WARC-Record-ID\":\"<urn:uuid:9e4ba85b-81e9-44ae-9d7d-ec88336d4d08>\",\"Content-Length\":\"49505\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6c3495ae-d609-4938-97a6-2ce4a09a7615>\",\"WARC-Concurrent-To\":\"<urn:uuid:856f17e3-33a8-4737-a22a-b104ad9b78b5>\",\"WARC-IP-Address\":\"142.251.45.115\",\"WARC-Target-URI\":\"https://tech.bragboy.com/2015/11/printing-permutation-of-characters-from.html\",\"WARC-Payload-Digest\":\"sha1:5HYU2PFZ2QTIMGWOQMEL36XCTM2Z36FJ\",\"WARC-Block-Digest\":\"sha1:ZPGU6LANT4NBGJSLRCG3EAXALYYYC4CU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323587711.69_warc_CC-MAIN-20211025123123-20211025153123-00115.warc.gz\"}"}