6 kyu
Reversing a Process
1,121 of 2,905g964
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
This comment has been hidden.
This comment has been hidden.
Interesting one.
PHP
translationApproved by someone
Approved by me, seems fine.
I am stuck on why it is impossible to decode? I thought if the encoded text is 66% similar to the decoded, it is impossible to decode? But that seems like not the case. What am I missing?
had fun solving this one.
Sample from task is working:
Letter: m | 12 * 6015 % 26 = 4 == e
Letter: e | 4 * 6015 % 26 = 10 == k
Letter: r | 17 * 6015 % 26 = 23 == x
But trying five letters from first test:
request = "1273409kuqhkoynvvknsdwljantzkpnmfgf" and answer must be "uogbucwnddunktsjfanzlurnyxmx"
Letter: k | 10 * 1273409 % 26 = 18 == s
Letter: u | 20 * 1273409 % 26 = 10 == k
Letter: q | 16 * 1273409 % 26 = 8 == i
Letter: h | 7 * 1273409 % 26 = 23 == x
Letter: k | 10 * 1273409 % 26 = 18 == s
None of the letters match. Maybe I didn't understand the task?
you are trying to encode the string again, decode it
Thank you! understood the mistake) Confused in the task
Spent an hour on this, really good one
Thanks!
This comment has been hidden.
This comment has been hidden.
Don't waste your time on this. The description is misleading and you have to figure out why decoding might be impossible. Didn't like it.
I understand your frustration.
Software Developer's reality lies somewhere between a very clear description and "mind reading". A certain level of self-research is almost inevitable. You might need to perform some digging to advise a customer on the best approach or, as in this case, find out why solving particular cases is impossible.
Considering this is not a white kata (levels 7 and 8) I think some amount of research is appropriate.
I'm coding it in Java, I fail these tests:
Input: 105860ymmgegeeiwaigsqkcaeguicc Expected: Impossible to decode Result: lmmgegeeijaigfdkcaeghicc
I tried encoding lmmgegeeijaigfdkcaeghicc with 105860 and I get 105860ymmgegeeiwaigsqkcaeguicc, so I think the expected Impossible to decode is wrong in the tests.
Another test where I get the original input when encoding the result: Input: 1877138eieaqgumigywmicwgcgg Expected: Impossible to decode Result: khkabclehcidehfdcfcc
Did anyone else have the same results as me?
Look at the top of the page: 258 people out of a total of 2,082 passed the Java kata. If tests were wrong somebody would have seen that before you. There are no errors in the tests.
I just ran into the same issue and your reply is not of any help. The description didn't specifically say why
lmmgegeeijaigfdkcaeghicc
shouldn't pass for105860ymmgegeeiwaigsqkcaeguicc
.I know I might be missing a hint but that's what questions/discussions are meant for, to point you in the direction of the hint you are missing not in the direction of the number of people that have solved the kata.
Who has a problem with "Unable to decode". Think logically why you are getting a response, but the response should be "Unable to decrypt". This is just for logic.
I have this problem. The ones that work are passing, but the ones that should be impossible are producing a string. I've already forfeited and looked at the solutions as I was spending way too long on this, but I can't for the life of me figure out why what I did doesn't work even though it's extremely similar to the solution listed first.
This comment has been hidden.
I understand perfectly the encoding part, but I don;t have no idea how to start the decoding part. Any help ?! PLease
This comment has been hidden.
This comment has been hidden.
This was great fun! :D
This comment has been hidden.
This one was cool.
I was surprised when none of the solutions I saw directly computed the multiplicative inverse modulo 26 of
num
to solve this problem.The multiplicative inverse modulo 26 of
num
is defined as the integerinverse
such that(num * inverse) % 26 = 1
. It is guarenteed to exist ifgcd(num, 26) = 1
. It's straightforward to see thatinverse
has the property that ify = (num * x) % 26
then(inverse * y) % 26 = x % 26
, allowing you to decode each character in constant time without constructing a lookup table.You can find the inverse using the Extended Euclidean algorithm.
I think the main insight that this approach provides is a simple condition for when the string cannot be decoded, i.e. when
gcd(num, 26) != 1
.Hi, I just join and see the solutions after I submit that one, and I used the way you say because I was first ask to help on this problem as a math problem (no computer) before the student told me it was for this website. Mine is longer because I am a full beginner in Python and didn't know about join or enumerate, and just tried to make it simple. Now, looking at the others solutions, I only see as marked "clever" very short solutions (in lines of code) and before I saw your comment I didn't even see your solution.
The hardest thing is to undestand why some numbers lead to "Impossible to decode". I am still not sure why . . .
This comment has been hidden.
!
Ruby 3.0 should be enabled, read this to learn how to do it
Please organize the structure of test fixture as following (although it has been mentioned in the attached link, I'm repeated here again)
Enabled in this fork
I cannot understand why aab -> aan is defined as impossible to decode. Some replies about this are hidden. Can anyone help? Thanks!
This comment has been hidden.
This comment has been hidden.
Very nice kata! Tricky part is finding out when it is 'impossible to decode'. Look at the second last post in this discussion and expand it. This might help you!
Just solved it, though it took time. To my point of view this is an easy kata. The problem is that the description does not help at all.
Really enjoyed this kata
Thanks!
Nica kata :)
Thanks!
This comment has been hidden.
The tests for kotlin are they correct??
"1877138eieaqgumigywmicwgcgg" -> "Impossible to decode"
"mymawsikysuokygosgss" -> My result
This comment has been hidden.
Yes the tests are correct. Read @ecolban post at the very end of discourses (penultimate post, unfold it).
It worked! Thanks g964! I saw my mistake...
Good!
This was a nice one. Definitely took some time but it was fun.
Thanks!
This comment has been hidden.
This comment has been hidden.
You could read some of the posts below, maybe it could help you. Some numbers are such that it is impossible to decode correctly whatever the string following the number.
This comment has been hidden.
This comment has been hidden.
Yes, I think that it would be more precise.
Done, thanks again.
Thank you for creating the kata, g964, it was fun to solve.
It was indeed a great kata and really took some time to solve it :)
Thanks!
This comment has been hidden.
Unfortunately there is nothing to update. 105860 is not a valid number for decoding. You could read comments below and try to understand why.
Your process of identifying invalid numvers is incorrect; sorry.
Thanks! Will try a different method then.
Good, you passed but maybe your condition for "Impossible to decode" could be clearer?:-)
With my draft solution, I have decoded "105860ymmgegeeiwaigsqkcaeguicc" getting "lmmgegeeijaigfdkcaeghicc". The basic test result expects "Impossible to decode", but when I encode "lmmgegeeijaigfdkcaeghicc" I get exactly "105860ymmgegeeiwaigsqkcaeguicc". Does anybody see the same situation?
I ran into the same problem
same here. From my point of view there is always a solution. Can't figure out the case when "positive integer num has not been correctly chosen"
Please be sure that there is no error in the tests. Otherwise how would you explain that about 900 guys passed the kata?
I have the same problem. What is criteria of "positive integer num has not been correctly chosen". Thank you (js)
It is up to you to find.
finally solved it... thank or the kata!!
Good and thanks!
exact same situation . . . feeling a little stumped.
Feel like there's a "trick" and I don't see it. Grrrr!
This comment has been hidden.
The tests are correct. Please read at the bottom of discourses @ecolban answer. Sorry, giving a hint would be to give the solution.
"761328qockcouoqmoayqwmkkic" gives me 'jdgegdidjkdahjbkeelg' but the test says it is impossible to decode, why is this so? I created a code function to reverse the reverse and 'jdgegdidjkdahjbkeelg' does give me "761328qockcouoqmoayqwmkkic".
Same.
same here
I even try the example "5057aan", which also should be impossible to decode. But I decode it successfully, with the result "ccb". Then encode it again in the exact same way as for example, and the encoded result is "5057ann". I don't understand what makes it impossible to decode...
I have same question
Please read at the bottom of discourses @ecolban answer. Sorry, giving a hint would be to give the solution.
Ah ic, thnx for the reply- misunderstood what impossible to decode was supposed to be for
I don't see @ecolban answer in this comment thread
At the bottom of the discourse page, before the very last test.
This comment has been hidden.
In most languages % is the modulo operator and not division.
Elon musk
In most languages? Is there even a single language where the modulo operator is used for division?
check the order of the operation :)
Ruby translation kumited -- please check and approve
I approved without checking, I trust you. You should have asked:-) My Ruby translation was written for my shell translation who needs Ruby testing. Poor me:-)
Well, you will hopefully get some ruby testing now :-) And worry not, I'm here if something is not right.
Cheers
This comment has been hidden.
@anter69 The Ruby reference solution relies on
CHARS
constant in the user's solution asCHARS
isn't defined in the test cases section.Thanks, fixed
This comment has been hidden.
this is broken. I am returning "Impossible to decode" and it is still failing all the test cases.
the kata's of user: g964 always strange and have weird test cases and description
I have some issue with description. What do you mean: "positive integer num has not been correctly chosen."?
It is a part of the kata that you have to find by yourself. The coding process is not always reversible.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Python solution overrides a builtin (
dict
), so the user won't be able to use it.Modified, thanks.
Are you serious? Users can't use
dict
because somebody else overrode it in their solution?This comment has been hidden.
?
lol
I took a chance. :]
G964 is free to reject my translation.
This comment has been hidden.
you cannot post code like that, you must use the spoiler tag otherwise everyone can see it in their dashboard
Not a suggestion.
Fack! I think that tests wrong, because that solutions successed:
decode(5057aan) -> aab
code(aab, 5057) -> 5057aan
I don't really understand your post since if you add the test:
testingDecode("5057aan", "aab")
you get:expected:<[aab]> but was:<[Impossible to decode]>
which is right.This comment has been hidden.
I am afraid that giving a hint will give the solution...
This comment has been hidden.
can anyone tell me how should i handle a sentence like "Impossible to decode" should i loop for a single word or each letter .when i loop for every letter my encoding value is this "5057aanaaaannananaaana" how come it is 5057aan .what i'm missing ?
This comment has been hidden.
I still can't figure out when or how to decide if given string is imposible to decode. I read other answer but it still does not make sense to me. Could you provide one example(s) with calculation.
Never mind. Understood
Why is :"1877138eieaqgumigywmicwgcgg", Impossible to decode? My output is :"khkabclehcidehfdcfcc". What am I missing?
Same
Me too. Have you found the root cause?
Can somebody explain why the following random test code is impossible to decode: 5071066aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Since a=0 and 0*x%26=0 a should always decode to a and thus the decoded version should be aaaaaaaa... Am I missing something?
you're reasoning "in the wrong direction": could the original message be 'cccccc...'? or even 'lksjyhgkjnjhfs...'? How do you find that out?
I think this is not 6kyu task. Rather than 5. What do you think about?
This comment has been hidden.
This comment has been hidden.
can you explain what's meant by Impossible to decode? 5057aan gives aab. with the rest passing, my code fails the impossible to decode. Are you looking for a pattern
This comment has been hidden.
Right,thanks. That comes up with Impossible to Code.
To add to pawer13 explanation. When is a function not invertible?? Good luck my dudes
This comment has been hidden.
What happens if you try
code( "ccb", 5057 )
?Or
code( "aad", 5057 )
?Or
code( "ccd", 5057 )
? Orcode('jdgegdidjkdahjbkeelg', 761328)
?Thanks! I understood what I was wrong.
seems there is an issue with JS: https://www.codewars.com/kata/reviews/5daea1a3eb95540001e2053f/groups/5daeb79104ec910001a995b2?show-solutions=1
Thanks! Modified. The testing function was not effective. Works now.