6 kyu
Reversing a Process
1,117 of 2,897g964
Description:
Suppose we know the process by which a string s
was encoded to a string r
(see explanation below). The aim of the kata is to decode this string r
to get back the original string s
.
Explanation of the encoding process:
- input: a string
s
composed of lowercase letters from "a" to "z", and a positive integernum
- we know there is a correspondence between
abcde...uvwxyz
and0, 1, 2 ..., 23, 24, 25
:0 <-> a, 1 <-> b ...
- if
c
is a character ofs
whose corresponding number isx
, apply tox
the functionf: x-> f(x) = num * x % 26
, then findch
the corresponding character off(x)
- Accumulate all these
ch
in a stringr
- concatenate
num
andr
and return the result
For example:
encode("mer", 6015) --> "6015ekx"
m --> 12, 12 * 6015 % 26 = 4, 4 --> e
e --> 4, 4 * 6015 % 26 = 10, 10 --> k
r --> 17, 17 * 6015 % 26 = 23, 23 --> x
So we get "ekx", hence the output is "6015ekx"
Task
A string s
was encoded to string r
by the above process. complete the function to get back s
whenever it is possible.
Indeed it can happen that the decoding is impossible for strings composed of whatever letters from "a" to "z" when positive integer num has not been correctly chosen. In that case return "Impossible to decode"
.
Examples
decode "6015ekx" -> "mer"
decode "5057aan" -> "Impossible to decode"
Fundamentals
Similar Kata:
Stats:
Created | Oct 21, 2019 |
Published | Oct 21, 2019 |
Warriors Trained | 11881 |
Total Skips | 722 |
Total Code Submissions | 16588 |
Total Times Completed | 2897 |
Python Completions | 1117 |
JavaScript Completions | 714 |
Java Completions | 331 |
C++ Completions | 236 |
Scala Completions | 34 |
Kotlin Completions | 80 |
Groovy Completions | 12 |
C# Completions | 186 |
Shell Completions | 20 |
Rust Completions | 60 |
Haskell Completions | 39 |
Ruby Completions | 57 |
Haxe Completions | 5 |
Dart Completions | 73 |
Pascal Completions | 6 |
Lua Completions | 23 |
Perl Completions | 11 |
Raku Completions | 1 |
Elm Completions | 3 |
D Completions | 6 |
Erlang Completions | 3 |
Prolog Completions | 6 |
PHP Completions | 12 |
Total Stars | 337 |
% of votes with a positive feedback rating | 89% of 483 |
Total "Very Satisfied" Votes | 401 |
Total "Somewhat Satisfied" Votes | 56 |
Total "Not Satisfied" Votes | 26 |
Total Rank Assessments | 7 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |