Alien decipher
Description:
As part of the SETI program, you think you have discovered an alien langage, where each digit from '0' to '9' would be encoded in a sequence of 3 or 4 symbols among _
and |
.
Of course, there would be one distinct code for each digit.
You indeed received strange messages of two lines each, each line having:
- 10 digits with each digit from 0 to 9, only once,
- the corresponding encoded sequence with
|
and_
(same ordering than the digits above).
Example:
4573628901 _||_|___|_|_|____|||_||______||||__
0754296318 __||_|_||___||_|||________|_||___||
You guess those two lines could be sufficient to decipher the alien code, and you intend to use the same code to reply to aliens, sending your own encoded message...
But you couldn't find a solution by hand, and asked a fellow developer for some help.
You want a function, that takes as parameters (see prototype):
- the message to encode: a string of some digits from '0' to '9',
- the clues: an array of two pairs, each pair containing :
- a string of 10 characters including all the numbers from '0' to '9',
- a string of characters composed with the symbols
_
and|
corresponding to the first string, of course in the same order.
The function will return the encoded string corresponding to the message, using the same code that was used for the clues.
Example: with inputs ...
585571121004456
4573628901 _||_|___|_|_|____|||_||______||||__
0754296318 __||_|_||___||_|||________|_||___||
.. your function should return :
|___|||__|___|_|||__||__|||||____||__||_||__||_|_____
... because the only possible code for encoding the first 2 lines is to associate to each digit the following code:
'0' -> "__||"
'1' -> "||__"
'2' -> "|||"
'3' -> "_|_"
'4' -> "_||_"
'5' -> "|__"
'6' -> "___"
'7' -> "_|_|"
'8' -> "_||"
'9' -> "____"
Notes:
- All tests (including the random ones) are designed in order to give ONLY one solution. If you have time, figure out the cases when it should not be the case...
- All input strings are valid (the purpose of this kata is only to play with algorithms)
- Fixed tests: about 50 tests with msg length between 5 and 10 included
- Random tests: about 1000 tests with msg length between 10 and 30. Serves as performance test as well if you don't pass rethink your solution...
Enjoy !
Similar Kata:
Stats:
Created | Aug 22, 2022 |
Published | Aug 22, 2022 |
Warriors Trained | 72 |
Total Skips | 22 |
Total Code Submissions | 35 |
Total Times Completed | 6 |
C++ Completions | 6 |
Total Stars | 7 |
% of votes with a positive feedback rating | 100% of 4 |
Total "Very Satisfied" Votes | 4 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 3 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |